Skip to content

Instantly share code, notes, and snippets.

@domeniconicoli
Last active January 5, 2023 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domeniconicoli/09fe4f9354d2868c66d219a87c663956 to your computer and use it in GitHub Desktop.
Save domeniconicoli/09fe4f9354d2868c66d219a87c663956 to your computer and use it in GitHub Desktop.
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