Skip to content

Instantly share code, notes, and snippets.

@ra9r
Last active September 28, 2022 09:56
Show Gist options
  • Select an option

  • Save ra9r/2dcabd925fca237ab878199176974b65 to your computer and use it in GitHub Desktop.

Select an option

Save ra9r/2dcabd925fca237ab878199176974b65 to your computer and use it in GitHub Desktop.
Example of how to authenticate with Biometrics
func signInWithBiometrics() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Please authenticate yourself to unlock your places."
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in
if success {
Task { @MainActor in
self.userProfile.isAuthenticated = true
}
} else {
if let error {
self.errorMessage = error.localizedDescription
}
}
}
} else {
// no biometrics
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment