Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let context = LAContext()
context.localizedCancelTitle = "Enter App's Passcode"
// First check if we have the needed hardware support.
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
let reason = "Access secure data"
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason ) { suc-
cess, error in
if success {
// The user passed Touch ID / Face ID Verification
// Grant him access to the secure data
} else {
print(error?.localizedDescription ?? "Failed to authenticate")
// The user failed Touch ID / Face ID Verification
}
// Fallback to: ask for passcode.
}
} else {
print(error?.localizedDescription ?? "Can't evaluate policy")
// Touch ID / Face ID not enrolled or no hardware support
// Fallback to: ask for passcode.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.