我目前正在实现一个仅接受触摸ID作为进入下一个viewcontroller的方式的应用程序,但作为一个新手,我不完全确定如何正确地执行此操作。我目前的代码如下:
-(void)viewWillAppear:(BOOL)animated {
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"Please Enter Touch ID";
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:@"showList" sender:nil];
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Authentication is verified through touch only."
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:nil, nil];
[alertView show];
// Rather than show a UIAlert here, use the error to determine if you should push to a keypad for PIN entry.
});
}
}];
}
}
每当用户点击“取消”按钮时,我的应用程序就会崩溃,但我希望它能够重新显示touchID验证。我怎么能这样做?谢谢你的帮助!