Contents

LAAuthenticationView

A graphical representation of the state of biometric authentication.

Declaration

class LAAuthenticationView

Overview

In the view that you use to manage authentication, add a local authentication view as a subview and provide it with an LAContext instance. For example, you can do this in the doc://com.apple.documentation/documentation/appkit/nsviewcontroller/loadview() method of your view controller:

func loadView() {
    laContext = LAContext()
    laView = LAAuthenticationView(context: laContext)

    view.addSubview(laView)
    laView.translatesAutoresizingMaskIntoConstraints = false

    // Add more subviews and layout constraints...
}

When the view appears, call the context’s evaluatePolicy(_:localizedReason:reply:) method to initiate the authentication:

override func viewDidAppear() {
    super.viewDidAppear()

    laContext.evaluatePolicy(
        .deviceOwnerAuthenticationWithBiometricsOrWatch,
        localizedReason: "access your data"
    ) { success, error in
        // Handle the result.
    }
}

The local authentication view displays an icon that depends on the type of authentication you request, and the types of authentication that the system supports. For example, for a device that supports Touch ID, if you request the deviceOwnerAuthenticationWithBiometricsOrWatch policy, like in the example above, the view displays the familiar finger print icon:

[Image]

In the case above, if the user has a connected Apple Watch, that authentication mechanism works as well. If you limit the authentication to the deviceOwnerAuthenticationWithWatch policy, the icon shows an Apple Watch in profile:

[Image]

You can include other content around this icon that suits your app. The system also displays a message on the Touch Bar or on the user’s Apple Watch, if appropriate. When the evaluation succeeds, the icon transitions into a checkmark:

[Image]

If you call the evaluation without first attaching it to a local authentication view, the system shows a standard authentication alert instead.

Topics

Creating a local authentication view

Controlling the size of a local authentication view