Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
Hi guys, I try to implement Touch Id for login in an application I develop but I need help about error handling. My problem is how to show up pin pad in a logging problem. Is there a default pin pad screen like Apple use or we have to design it as an developer? Here my code is
Code:
LAContext *laContext = [[LAContext alloc] init];
    NSError *error = nil;
    NSString *warningString = @"Used for quick and secure access to the application";
    
    if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
        [laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:warningString reply:^(BOOL success, NSError * _Nullable error) {
            if (success) {
                dispatch_async(dispatch_get_main_queue(), ^{
                   [self performSegueWithIdentifier:@"successSegue" sender:nil];
                });
                
            } else {
                switch ([error code]) {
                    case LAErrorAuthenticationFailed: {
                        NSLog(@"AUTHENTICATION FAILED");
                        break;
                    }
                        
                    case LAErrorUserFallback: {
                        NSLog(@"KLAVYE GÖSTER");
                        break;
                    }
                        
                    case LAErrorUserCancel: {
                        NSLog(@"USER CANCELED");
                        break;
                    }
                        
                    default:
                        break;
                }
                
            }
        }];
    } else {
        dispatch_async(dispatch_get_main_queue(), ^{
            UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Warning" message:@"This feature is not supported by the device" preferredStyle:UIAlertControllerStyleAlert];
            [controller addAction:[UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }]];
            [self presentViewController:controller animated:true completion:nil];
        });
    }
 
You design your own screen for the username/password or app pin.

When the Face ID or Touch ID fail the user is prompted to try again or cancel. If the user chooses cancel, take them to your custom manual login screen.


Implementing biometrics is complicated. I suggest searching for some blog discussions on it and reading everything that Apple has.

There is a limit to how many times a user can retry the biometric id. Also, too many false attempts cause a global lockout of using the biometric system and the only way to fix that is for the user to tap the power button to logout of the device. Then they can log back in using their device passcode. Being locked out from biometrics does NOT stop the user from using standard text login views.


P.S. When you save passwords or pins locally, you should be using the keychain using its secure methods.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.