iOSer 的自我修养不常用,倒是可以装逼iOS 开发

iOS 指纹识别

2016-06-02  本文已影响307人  倚楼听风雨wing
touch.png

1.单词介绍##

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

2.使用方式##

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

- (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");
    }
}

上一篇下一篇

猜你喜欢

热点阅读