-
-
Save domeniconicoli/09fe4f9354d2868c66d219a87c663956 to your computer and use it in GitHub Desktop.
This file contains 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 authenticationWithTouchID() { | |
let localAuthenticationContext = LAContext() | |
localAuthenticationContext.localizedFallbackTitle = "Please use your Passcode" | |
var authorizationError: NSError? | |
let reason = "Authentication required to access the secure data" | |
if localAuthenticationContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &authorizationError) { | |
localAuthenticationContext.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { success, evaluateError in | |
if success { | |
DispatchQueue.main.async() { | |
let alert = UIAlertController(title: "Success", message: "Authenticated succesfully!", preferredStyle: UIAlertController.Style.alert) | |
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) | |
self.present(alert, animated: true, completion: nil) | |
} | |
} else { | |
// Failed to authenticate | |
guard let error = evaluateError else { | |
return | |
} | |
print(error) | |
} | |
} | |
} else { | |
guard let error = authorizationError else { | |
return | |
} | |
print(error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment