TouchID:如何获取Touch ID身份验证尝试次数?

3

我需要实现Touch ID并向用户显示身份验证尝试的警报。以下是我使用的代码。

在一次错误的身份验证尝试后,回复块没有被调用。它在连续3次错误的身份验证尝试后才会被调用。有没有办法获取错误身份验证尝试的计数?

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];
    });
}
1个回答

4
我阅读了文档,无法在每次失败的尝试中显示警报。只需参考iOS中的LocalAuthentication文档。

您可以在不同的错误情况下显示警报。第三次失败后将调用LAError.authenticationFailed,第五次失败后将调用LAError.touchIDLockout。您可以在这里显示警报。有关更多信息,请参见Apple LAError文档。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接