第一步:老地方导入第三方库:LocalAuthentication.framework
第二步:在需要指纹解锁的地方导入头文件
#import "LocalAuthentication/LAContext.h"
第三步:关键代码
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
LAContext * muContext = [[LAContext alloc]init];
NSError * autherror = nil;
NSString *myLocalizedReasonString = @"We need to verify your fingerprint to confirm your identity";
if ([muContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&autherror]) {
[muContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
NSLog(@"指纹验证成功");
}else{
//验证三次不成功就会走这个方法
NSLog(@"指纹验证失败");
}
}];
}else{
NSLog(@"系统没有开启指纹模式,或者用户多次验证指纹失败!");
}
}
结束!!!!