2

Im trying to create an app with Face id feature. But when I try to handle the error codes, i can only catch the LAErrorUserCancel. I was unable to catch other error codes such as LAErrorAuthenticationFailed.

        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"asd"   reply:
         ^(BOOL success, NSError *authenticationError) {

             if (success) {
                 [[NSOperationQueue mainQueue] addOperationWithBlock:^(void){
                     [NSTimer scheduledTimerWithTimeInterval:1/40
                                                      target:self
                                                    selector:@selector(registerTouchID)
                                                    userInfo:nil
                                                     repeats:NO];
                 }];
             }
             else {
                 switch (authenticationError.code) {
                     case LAErrorAuthenticationFailed:
                         dispatch_async(dispatch_get_main_queue(), ^{
                            [self TouchFail];
                         });
                         break;

                     case LAErrorUserCancel:
                         NSLog(@"User pressed Cancel button");
                         break;

                     case LAErrorUserFallback:
                         NSLog(@"User pressed \"Enter Password\"");
                         break;

                     case LAErrorBiometryLockout:
                         dispatch_async(dispatch_get_main_queue(), ^{
                             [self LockoutAlert];
                         });
                         break;
                     default:
                         break;
                 }
             }
         }];
Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93

2 Answers2

1

Currently, iOS will show "Cancel" button after failed FaceID attempts. That's why we're getting "LAErrorUserCancel".

For TouchID it returns "LAErrorAuthenticationFailed"

Thafer Shahin
  • 814
  • 9
  • 10
-2

You can get the error code by error. _code =-6 or -4 like that...

Just use PO statement in logs to get the error and handle accordingly.

  • Please provide more insight into why this is the proper solution compared to what OP already attempted in their question. FWIW, it is typically helpful to provide code snippets and/or a clear description of intent in order to give users more context. – pxpgraphics Mar 30 '20 at 04:43