TouchID forward to system passcode authentication

eric picture eric · Aug 20, 2014 · Viewed 9.9k times · Source

I want to use TouchID authenticate my own app.

1.I want user can click 'Enter passcode' to invoke system build-in passcode screen to authenticate,if success then enter my own app.
But I don't how know to make it forward to passcode authenticate view like the following screen in 'case LAErrorUserFallback' enter image description here

Here is my code :

LAContext *context = [[LAContext alloc] init];
__block  NSString *msg;
__block  BOOL bAuth;
// show the authentication UI with our reason string
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"Unlock APP With FingerPrint", nil) reply:
^(BOOL success, NSError *authenticationError) {

   if (success) {
      bAuth = YES;
      msg =[NSString stringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_SUCCESS", nil)];
      dispatch_async(dispatch_get_main_queue(), ^{
         [[MYAppDelegate theDelegate] initializeAppAfterKeyVaultUnlocked];
      });
      NSLog(@"%@",msg);
   } else {
      bAuth = NO;
      switch (authenticationError.code) {
         case LAErrorAuthenticationFailed:
            msg = [NSString stringWithFormat:NSLocalizedString(@"Authentication Failed", nil)];
            // ...
            break;

         case LAErrorUserCancel:
            msg = [NSString stringWithFormat:NSLocalizedString(@"User pressed Cancel button", nil)];
            dispatch_async(dispatch_get_main_queue(), ^{
               [[MYAppDelegate theDelegate] exitAndLock];
            });

            break;

         case LAErrorUserFallback:
            msg = [NSString stringWithFormat:NSLocalizedString(@"User pressed \"Enter Password\"", nil)];
            //Here I want to fallback to iOS build-in passcode authenticate view, and get the auth result.
            break;

         default:
            msg = [NSString stringWithFormat:NSLocalizedString(@"Touch ID is not configured", nil)];
            // ...
            break;
      }
      NSLog(@"%@",authenticationError.localizedDescription);

   }


}];

Answer

Dannie P picture Dannie P · May 15, 2016

Now in iOS 9 it is pretty simple actually - you just have to use LAPolicyDeviceOwnerAuthentication instead of LAPolicyDeviceOwnerAuthenticationWithBiometrics

So in your code you just replace this:

[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"Unlock APP With FingerPrint", nil) reply:
^(BOOL success, NSError *authenticationError) {

With this:

[context evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:NSLocalizedString(@"Unlock APP With FingerPrint", nil) reply:
^(BOOL success, NSError *authenticationError) {

Thus, when user fails to authenticate with fingerprint, there'd be "enter passcode" option which would invoke system passcode input screen.