必威体育Betway必威体育官网
当前位置:首页 > IT技术

TouchID

时间:2019-07-16 22:40:00来源:IT技术作者:seo实验室小编阅读:64次「手机版」
 

touch id

iPhone的指纹解锁实际很简单的,但是需要8.0以后使用,苹果都给封装好了,在测试下面代码前,记得设置TouchID,下面上代码吧。

-(void)testTouchId
{
    NSERROR *error = nil;
    if ([self.context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
        NSLog(@"支持指纹识别");
        [self.context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"指纹解锁" reply:^(BOOL success, NSError * _Nullable error) {
            if (success) {
                NSLog(@"验证成功 刷新主界面");
            }else{
                NSLog(@"%@",error.localizedDescription);
                switch (error.code) {
                    case LAErrorSystemCancel:
                    {
                        NSLog(@"系统取消授权,如其他APP切入");
                        break;
                    }
                    case LAErrorUserCancel:
                    {
                        NSLog(@"用户取消验证touch id"); break;
                    }
                    case LAErrorAuthenticationFailed:
                    {
                        NSLog(@"授权失败"); break;
                    }
                    case LAErrorPasscodeNotSet:
                    {
                        NSLog(@"系统未设置密码"); break;
                    }
                    case LAErrorTouchIDNotAvailable:
                    {
                        NSLog(@"设备Touch ID不可用,例如未打开");
                        break;
                    }
                    case LAErrorTouchIDNotEnrolled:
                    {
                        NSLog(@"设备Touch ID不可用,用户未录入");
                        break;
                    }
                    case LAErrorUserFallback: {
                        [[NSOperationqueue mainQueue] addOperationWithBlock:^{ NSLog(@"用户选择输入密码,切换主线程处理"); }];
                        break;
                    }
                    default:
                    {
                        [[NSOperationQueue mainQueue] addOperationWithBlock:^{ NSLog(@"其他情况,切换主线程处理"); }];
                        break;
                    }
                }
            }
        }];
    }else{
        NSLog(@"不支持指纹识别");
        switch (error.code)
        {
            case LAErrorTouchIDNotEnrolled:
            {
                NSLog(@"TouchID is not enrolled");
                break;
            }
            case LAErrorPasscodeNotSet:
            {
                NSLog(@"A passcode has not been set");
                break;
            }
            default: {
                NSLog(@"TouchID not available");
                break;
              }
        }
        NSLog(@"%@",error.localizedDescription); }
}
-(LAContext *)context
{
    if (!_context) {
        _context = [LAContext new];
        _context.localizedCanceltitle = @"取消";
    }
    return _context;
}

相关阅读

分享到:

栏目导航

推荐阅读

热门阅读