Contents

LocalAuthenticationView

A SwiftUI view that displays an authentication interface.

Declaration

@MainActor @preconcurrency struct LocalAuthenticationView<Label> where Label : View

Overview

Use a LocalAuthenticationView to display a view that prompts users to authenticate with the app. The view visually represents the state of an LAPolicy evaluation from the Local Authentication framework.

The following shows a LocalAuthenticationView in a Mac app with an implicit LAContext instance:

var body: some View {
    LocalAuthenticationView(
        "Continue with Touch ID",
        reason: Text("Access sandcastle competition designs")
    ) { result in
        switch result {
        case .success:
            print("Authorized")
        case .failure(let error):
            print("Authorization failed: \(error)")
        }
    }
    .controlSize(.large)
}

If your app’s authorization flow reuses an existing LAContext, pass it as part of initializing a LocalAuthenticationView and call its evaluatePolicy(_:localizedReason:reply:) method after the view appears.

Topics

Authenticating with an implicit context

Authenticating with a context you supply

Initializers