Skip to content

Instantly share code, notes, and snippets.

@DejanEnspyra
Last active January 16, 2018 09:59
Show Gist options
  • Save DejanEnspyra/85a6d66edf1c434f05b01f1066e560a0 to your computer and use it in GitHub Desktop.
Save DejanEnspyra/85a6d66edf1c434f05b01f1066e560a0 to your computer and use it in GitHub Desktop.
Face ID and Touch ID Authentication using Swift
func authenticate(){
let context = LAContext()
let reason = "We need this to protect your payments." // add your own message explaining why you need this authentication method
var authError: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, error in
if success {
// User authenticated successfully
} else {
// User did not authenticate successfully
}
}
} else {
// Handle Error
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment