【发布时间】:2020-01-29 20:17:06
【问题描述】:
我创建了一个登录屏幕并希望允许用户使用生物识别进行身份验证。我可以显示 TouchID/FaceID 对话框,但我无法使用“取消”按钮将其关闭。它会暂时消失,然后重新出现。有没有一种简单的方法可以找出导致这种情况的原因。非常感谢。
更新:检查错误后,我在日志中收到以下内容:
Domain=com.apple.LocalAuthentication Code=-4 "被其他人取消 身份验证。”
代码:
@interface LoginViewController ()
@property (nonatomic, strong) LAContext *context;
@end
@implementation LoginViewController
- (LAContext *)context {
if (_context == nil) {
_context = [LAContext new];
}
return _context;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSError *error;
BOOL canAuthentication = [self.context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&error];
if (canAuthentication) {
[self.context evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:@"FaceID" reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
UIAlertController *alearC = [UIAlertController alertControllerWithTitle:@"Success" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alearC addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alearC animated:YES completion:nil];
} else {
NSLog(@"error%@",error);
}
}];
}
}
【问题讨论】:
标签: objective-c touch-id