iOS LAPolicyDeviceOwnerAuthentication“取消”按钮

时间:2017-03-12 06:48:45

标签: ios objective-c authentication

我目前正在我的应用中使用LAPolicyDeviceOwnerAuthentication来启动TouchID /密码验证。但是,如果用户点击“取消”,我的应用只会关闭touchID /密码验证并且什么都不做。有没有办法可以让它重新启动touchID验证过程?

以下是我目前正在尝试做的事情:

-(void)callAuthenticate {
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"Please Enter Touch ID";

if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthentication
              localizedReason:myLocalizedReasonString
                        reply:^(BOOL success, NSError *error) {
                            if (success) {
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    [self performSegueWithIdentifier:@"showList" sender:nil];
                                });
                            } else if (error){
                                NSString *errorMessage;
                                BOOL showError = NO;
                                switch (error.code) {
                                    case LAErrorAuthenticationFailed:
                                        errorMessage = @"Sorry couldn't autheticate";
                                        showError = YES;
                                        break;
                                    case LAErrorPasscodeNotSet:
                                        errorMessage = @"No Passcode has been set";
                                        showError = YES;
                                        break;
                                    case LAErrorTouchIDNotEnrolled:
                                        errorMessage = @"Touch ID has no enrolled fingers";
                                        showError = YES;
                                        break;
                                    default:
                                        showError = NO;
                                        break;
                                }
                                if (showError) {
                                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                                    message:errorMessage
                                                                                   delegate:nil
                                                                          cancelButtonTitle:@"Ok"
                                                                          otherButtonTitles:nil];
                                    [alert show];

                                }
                            }
                        }];
} else {
    [self performSegueWithIdentifier:@"showList" sender:nil];
}

}

感谢您的帮助! : - )

1 个答案:

答案 0 :(得分:1)

当错误代码为LAErrorUserCanceled时,您需要处理此案例。目前正由default:案件处理,该案件什么都不做。