Wednesday, June 10, 2015

Touch ID integration in iOS few notes

When integrating the touch ID, found that it takes a lot of time to return back from the authentication success state. Below code was added to mitigate this. The main part was the dispatch_async(dispatch_get_main_queue() in the success block. 

if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
    
    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
              localizedReason:myLocalizedReasonString
                        reply:^(BOOL success, NSError *error) {
     
     if (success) {
     // User authenticated successfully, take appropriate action
     dispatch_async(dispatch_get_main_queue(), ^{
                    // write all your code here
                    });
     } else {
     // User did not authenticate successfully, look at error and take appropriate action
     }
     
     }];
} else {
    // Could not evaluate policy; look at authError and present an appropriate message to user
}


Another item that left out of notice was the use of “Enter password”. When clicking on Enter password on the popup, it calls back with any of the below errors depending on the scenario


case UserCancel
case UserFallback
case SystemCancel
case PasscodeNotSet
case TouchIDNotAvailable
case TouchIDNotEnrolled
case TouchIDLockout
case AppCancel

appliation can then redirect to an existing password text field within the app possibly 

References:

No comments:

Post a Comment