为什么不能关闭Touch ID提示?

时间:2019-09-30 14:02:37

标签: objective-c touch-id

我已经创建了一个登录屏幕,并希望允许用户使用生物识别技术进行身份验证。我可以显示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);
            }
        }];
    }
}

1 个答案:

答案 0 :(得分:0)

这样做的原因通常是因为指纹扫描仪仍被先前的操作占用g。似乎您没有使用过cancellationSignal.cancel,或者好像没有使用过它。每次使用完扫描仪后,您都必须使用cancellationSignal.cancel发送信号,以表明扫描仪已完成工作。

例如,如果任务失败,则看起来像这样,

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

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

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

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

让我知道是否可以解决您的问题,否则我会调查

相关问题