LocalAuthenticationView
A SwiftUI view that displays an authentication interface.
Declaration
@MainActor @preconcurrency struct LocalAuthenticationView<Label> where Label : ViewOverview
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
init(reason:context:result:label:)init(_:reason:context:result:)init(_:reason:context:result:)init(_:reason:context:result:)