#import "ViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//指纹识别核心代码 // 创建本地认证上下文
LAContext *context = [[LAContext alloc] init];
// 检验设备是否支持指纹识别
// Biometrics:生物统计学 ,这里就是指纹识别
if(![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]){
NSLog(@"你的设备不支持指纹识别!");
return;
}
// 进行指纹识别
// localizedReason: 你为什么需要指纹识别
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"支付请录入指纹" reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
NSLog(@"指纹识别成功");
}else{
NSLog(@"指纹识别失败:%@",error);
}
}];
}
@end