【问题标题】:Why can't I dismiss the Touch ID prompt?为什么我无法关闭 Touch ID 提示?
【发布时间】: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


    【解决方案1】:

    造成这种情况的原因通常是因为指纹扫描仪仍被先前的操作占用。似乎您没有使用过cancellationSignal.cancel,或者如果您有它可能没有被触发。每次扫描仪完成使用时,您都必须使用cancellationSignal.cancel 发送信号,表示扫描仪已完成工作。

    例如,如果任务失败,那么它看起来像这样,

    text_state.setText(context.getString(R.string.fingerFailure));
    cancellationSignal.cancel();
    

    尝试在此上方或下方添加cancellationSignal.cancel()

    [self presentViewController:alearC animated:YES completion:nil];
    

    如果需要,也可以在 else 块中使用。

    如果这能解决您的问题,请告诉我,如果没有,我会调查它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-11
      • 2022-01-24
      • 1970-01-01
      • 2016-06-19
      • 2021-07-30
      • 1970-01-01
      相关资源
      最近更新 更多