iOS 8 SDK by Apple provides Local Authentication API that allows developers to integrate Touch Id authentication in applications.
To integrate Touch Id authentication follow the below steps:
- Import Local Authentication framework in your controller.
import LocalAuthentication
- Use the following function to the authentic user:
func authenticateUser(){
let authenticationContext = LAContext()
var error:NSError?
// 2. Check if the device has a fingerprint sensor
// If not, show the user an alert view and bail out!
guard authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
// SHOW MESSAGE HERE
return
}
// 3. Check the fingerprint
authenticationContext.evaluatePolicy(
.deviceOwnerAuthenticationWithBiometrics,
localizedReason: "Identify Yourself",
reply: { [unowned self] (success, error) -> Void in
if( success ) {
// Fingerprint recognized
// The success code goes here
}else {
// Check if there is an error
if let error = error {
// Error Occured
// The error code goes here
}
}
})
}
0 Comment(s)