Skip to content

Instantly share code, notes, and snippets.

@kurtisdunn
Created July 11, 2015 12:36
Show Gist options
  • Save kurtisdunn/4bfff77259c1282e95f0 to your computer and use it in GitHub Desktop.
Save kurtisdunn/4bfff77259c1282e95f0 to your computer and use it in GitHub Desktop.
Touch ID Swift
let myContext = LAContext()
var authError: NSError?
// Set the reason string that will appear on the authentication alert.
var myReasonString = "String explaining why app needs authentication"
if myContext.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &authError) {
[myContext.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: myReasonString, reply: { (success: Bool, evalPolicyError: NSError?) -> Void in
if success {
// User authenticated successfully
} else {
// Authenticate failed
}
})]
} else{
// Could not evaluate policy; check authError
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment