TouchID: How to get authentication attempts while trying to authenticate?

I need to implement a touch id and show the user a warning about authentication attempts. Below is the code I'm using.

a response block will not be called after one invalid authentication attempt. Calling it after 3 continues the failed authentication attempt. Is there a way to get the number of failed authentication attempts.?

LAContext *myContext = [[LAContext alloc] init];

NSError *authError = nil;
NSString *myLocalizedReasonString = @"Touch ID Test to show Touch ID working in a custom app";

if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
              localizedReason:myLocalizedReasonString
                        reply:^(BOOL success, NSError *error) {
                            if (success) {
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    [self performSegueWithIdentifier:@"Success" sender:nil];
                                });
                            } else {
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                                        message:error.description
                                                                                       delegate:self
                                                                              cancelButtonTitle:@"OK"
                                                                              otherButtonTitles:nil, nil];
                                    [alertView show];
                                    NSLog(@"Switch to fall back authentication - ie, display a keypad or password entry box");
                                });
                            }
                        }];
} else {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                            message:authError.description
                                                           delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil, nil];
        [alertView show];
    });
}

      

+3


source to share


1 answer


I went through the documentation, in every failed attempt it is impossible to show a warning. Just refer to the iOS Local Authentication documentation .

You can display warnings for different error cases. After the 3rd unsuccessful attempt, LAError.authenticationFailed is called and after the 5th unsuccessful attempt, LAError.touchIDLockout will be called . You can display warnings here. For more information, see Apple's LAError documentation.



+4


source







All Articles