Last active
September 28, 2022 09:56
-
-
Save ra9r/2dcabd925fca237ab878199176974b65 to your computer and use it in GitHub Desktop.
Example of how to authenticate with Biometrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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