您的位置:首页 > 编程语言 > C语言/C++

OC语言实现指纹识别

2016-04-07 13:42 211 查看
简单实现指纹识别的方法,大虾勿喷~

1、引入类

#import <LocalAuthentication/LocalAuthentication.h>
2、实现方法
- (void) anthTouchID:(NSString *) describe complete:(void(^)(NSString *backStr)) complete
{
//检查操作系统是否达到指纹识别要求
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){

//检查Touch ID是否可用
LAContext *anthContext = [[LAContext alloc]init];
NSError *error = [[NSError alloc]init];

BOOL touchIDAvailable = [anthContext canEvaluatePolicy:kLAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];

if (touchIDAvailable) {

//指纹识别可用,获取验证结果
[anthContext evaluatePolicy:kLAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:describe reply:^(BOOL success, NSError * _Nullable error) {

//加入主线程中执行
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {

//验证通过
if (complete) {
complete(@"success");
}

} else {

//验证失败
if (complete) {
complete(error.localizedDescription);
}
}
});
}];

} else {

//指纹识别不可用
if (complete) {
complete(error.localizedDescription);
}
}

} else {

//设备操作系统版本过低
if (complete) {
complete(@"Device system version too low.");
}
}
}


3、调用方法
[self anthTouchID:@"指纹识别的测试调用" complete:^(NSString *backStr) {
NSLog(@"输出:%@",backStr);
}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: