IOS TouchID 指纹解锁

ViewController.m

Demo :http://pan.baidu.com/disk/home#list/path=%2FIOS%E5%BC%80%E5%8F%91Demo

  //使用TouchID必须导入这个库
#import <LocalAuthentication/LocalAuthentication.h>

//判断系统大于8.0
#define iOS8  ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0)


//点击按钮调用TouchID功能
- (IBAction)TouchIDBtn:(id)sender {
if (!iOS8) {
    //低于8.0直接返回
    return;
}
//调用touchID
[self toucheIDShow];
}

- (void)toucheIDShow {


// 创建指纹验证对象
LAContext *context = [[LAContext alloc] init];

NSError *error = nil;


// 验证其是否支持touchID
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
    
    // 如果支持的话就开启touchID
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"通过Home键验证已用手机指纹" reply:^(BOOL success, NSError * _Nullable error) {
        if (success) {
            // 验证成功,在这里做验证成功的操作
           self.label.text = @"验证成功";
        }
        else {
            self.label.text = @"验证失败";
            NSLog(@"errorCode--%ld,error%@",error.code,error.localizedDescription);
//                self.label.text = @"验证失败";
        }
    }];
}
else {
    // 不支持touchID打印错误
    if (error) {
        NSLog(@"%@",error.localizedDescription);
    }
}
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容