Skip to content

Instantly share code, notes, and snippets.

@apple-avadhesh
Created April 29, 2017 14:23
Show Gist options
  • Save apple-avadhesh/fd953c110d221192e22373c510ec4766 to your computer and use it in GitHub Desktop.
Save apple-avadhesh/fd953c110d221192e22373c510ec4766 to your computer and use it in GitHub Desktop.
Touch Id Authentication
import UIKit
import LocalAuthentication
func requestFingerprintAuthentication() {
let context = LAContext()
var authError: NSError?
let authenticationReason: String = "To display a message to the user"
if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: authenticationReason, reply: {
(success: Bool, error: NSError?) -> Void in
if success {
print("Success")
} else {
print("Unable to Authenticate")
}
} as! (Bool, Error?) -> Void)
}
}
func updateMessageLabel(message: String) {
DispatchQueue.main.async {
print(message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment