首先引入类名:
#import <LocalAuthentication/LocalAuthentication.h>
其次:
LAContext * authenticationContext = [[LAContext alloc] init];
NSError * error = [[NSError alloc] init];
BOOL isTouchIdAvailable = [authenticationContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];
if (isTouchIdAvailable ) {
NSLog(@"认证策略成功");
//可以进行指纹识别认证,在Home键录入指纹比对
[authenticationContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometricslocalizedReason:@"需要验证您的指纹来确认您的身份信息" reply:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"恭喜,您通过了Touch ID指纹验证!");
}else {
NSLog(@"抱歉,您未通过了Touch ID指纹验证!");
}
}];
}else {
NSLog(@"认证策略失败,error === %@",error);
}