简单实现指纹识别的方法,大虾勿喷~
1、引入类
#import
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);
}];
本文介绍了一种简单的iOS平台上的指纹识别实现方法。首先通过引入必要的类来支持Touch ID功能,然后实现了具体的验证流程,包括检查系统版本、Touch ID的可用性,并通过回调返回验证结果。

被折叠的 条评论
为什么被折叠?



