jstart
7/31/2014 - 9:34 PM

Touch ID Example

Touch ID Example

LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"Authenticate using your finger";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
   [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                 localizedReason:myLocalizedReasonString
                           reply:^(BOOL success, NSError *error) {
                               if (success) {
                                   NSLog(@"User is authenticated successfully");
                               } else {
                                   switch (error.code) {
                                       case LAErrorAuthenticationFailed:
                                           NSLog(@"Authentication Failed");
                                           break;
                                            
                                       case LAErrorUserCancel:
                                           NSLog(@"User pressed Cancel button");
                                           break;
                                            
                                       case LAErrorUserFallback:
                                           NSLog(@"User pressed \"Enter Password\"");
                                           break;
                                            
                                       default:
                                           NSLog(@"Touch ID is not configured");
                                           break;
                                   }
                                   NSLog(@"Authentication Fails");
                               }
                           }];
} else {
   NSLog(@"Can not evaluate Touch ID");
}