iOS 指纹识别

iOS 指纹识别_第1张图片
touch.png

1.单词介绍##

这里涉及到的很多单词都比较生僻,所以我给出注解,希望能帮助大家更好的理解使用苹果的这个API

  • Local: 本地
  • Authentication: 验证
  • Evaluate: 评估
  • policy: 政策/方针/策略
  • Biometrics: 生物识别技术

2.使用方式##

导入头文件:#import
例如在触摸屏幕的时候弹出指纹识别

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // 1. 判断iOS8.0及以上版本  从iOS8.0开始才有的指纹识别
    if (![UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
        NSLog(@"当前系统暂不支持指纹识别");
        return;
    }
    
    // 2. 创建LAContext对象 --> 本地验证对象上下文
    LAContext *context = [LAContext new];
 
    // 3.判断用户是否设置了Touch ID
    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
        //4. 开始使用指纹识别
        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"指纹验证登录" reply:^(BOOL success, NSError *error) {
            //4.1 验证成功
            if (success) {
                NSLog(@"验证成功");
            }
            
            //4.2 验证失败
            NSLog(@"error: %ld",error.code);
            
            if (error.code == -2) {
                NSLog(@"用户自己取消");
            }
            
            if (error.code != 0 && error.code != -2) {
                NSLog(@"验证失败");
            }
        }];
    } else {
        NSLog(@"请先设置Touch ID");
    }
}

你可能感兴趣的:(iOS 指纹识别)