1 -(void)CreateFingerPrint{ 2 LAContext *myContext = [[LAContext alloc] init]; 3 NSError *authError = nil; 4 NSString *myLocalizedReasonString = @"请验证已有指纹"; 5 6 // 判断设备是否支持指纹识别 7 if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { 8 if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"zhiwenshibie"]isEqualToString:[Finance_Tools getUserID]]) { 10 // 指纹识别只判断当前用户是否机主 12 [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 13 localizedReason:myLocalizedReasonString 14 reply:^(BOOL success, NSError *error) { 15 if (success) { 16 // User authenticated successfully, take appropriate action 17 NSLog(@"指纹认证成功"); 18 dispatch_async(dispatch_get_main_queue(), ^{ 19 20 [self createTiXianDownload:[[NSUserDefaults standardUserDefaults] objectForKey:@"PassWord"]]; 21 }); 26 } else { 27 NSLog(@"指纹认证失败,%@",error.description); 28 29 dispatch_async(dispatch_get_main_queue(), ^{ 30 31 //回到主线程操作代码块 32 if ([[@(error.code) stringValue] isEqualToString:@"-2"]||[[@(error.code) stringValue] isEqualToString:@"-4"]) { 33 }else if ([[@(error.code) stringValue] isEqualToString:@"-3"]||[[@(error.code) stringValue] isEqualToString:@"-8"]||[[@(error.code) stringValue] isEqualToString:@"-1"]){ 34 //失败原因,弹出弹框输入密码 35 36 } 37 38 }); 39 40 41 } 42 }]; 43 44 }else{ 45 //开启指纹识别 46 } 47 } else { 48 // Could not evaluate policy; look at authError and present an appropriate message to user 49 NSLog(@"TouchID设备不可用"); 50 // TouchID没有设置指纹 51 // 关闭密码(系统如果没有设置密码TouchID无法启用) 52 53//弹出弹框输入密码 56}
57}
失败原因:
1 NSLog(@"指纹认证失败,%@",error.description); 2 // 错误码 error.code 3 // -1: 连续三次指纹识别错误 4 // -2: 在TouchID对话框中点击了取消按钮 5 // -3: 在TouchID对话框中点击了输入密码按钮 6 // -4: TouchID对话框被系统取消,例如按下Home或者电源键 7 // -8: 连续五次指纹识别错误,TouchID功能被锁定,下一次需要输入系统密码 8
时间: 2024-10-21 10:59:51