先导入一个库文件
#import <LocalAuthentication/LocalAuthentication.h>
//此方法专门用来印证用户的指纹
- (void)anthenticationUser
{
LAContext *content = [[LAContextalloc] init];
content.localizedFallbackTitle =@"输入密码";
NSError *error =nil;
NSString *text =@"请验证已有指纹";
if ([contentcanEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometricserror:&error]) {
[content evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometricslocalizedReason:text reply:^(BOOL success,NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
[selfshowHud:@"指纹验证成功"];
}else{
DLog(@"error.description = %@ %@",error.description,error.userInfo);
NSString *errorDescription;
if (error.code ==LAErrorAuthenticationFailed) {
errorDescription = @"指纹认证失败";
}
//iOS9.0
// else if (error.code == LAErrorAppCancel) {
// errorDescription = @"认证被APP取消";
// }
elseif (error.code ==LAErrorSystemCancel) {
errorDescription = @"认证被系统取消";
}elseif (error.code ==LAErrorUserCancel) {
errorDescription = @"点击取消按钮";
}elseif (error.code ==LAErrorUserFallback) {
errorDescription = @"点击输入密码按钮";
}else{
errorDescription = @"指纹验证失败";
}
DLog(@"%@",errorDescription);
[selfshowHud:errorDescription];
}
});
}];
}else{
DLog(@"error.description = %@ %@",error.description,error.userInfo);
dispatch_async(dispatch_get_main_queue(), ^{
NSString *errorDescription;
if (error.code ==LAErrorTouchIDNotAvailable) {
errorDescription = @"Touch ID不可用";
}elseif (error.code ==LAErrorTouchIDNotEnrolled) {
errorDescription = @"TouchID尚未被录入";
}
//iOS9.0
// else if (error.code == LAErrorTouchIDLockout) {
// errorDescription = @"失败次数过多,请输入密码解锁";
// }
elseif (error.code ==LAErrorPasscodeNotSet) {
errorDescription = @"尚未设置密码";
}else{
errorDescription = @"该设备不支持Touch ID";
}
DLog(@"%@",errorDescription);
[selfshowHud:errorDescription];
});
}
}