iOS指纹识别

-(void)CreateFingerPrint{
    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;
    NSString *myLocalizedReasonString = @"请验证已有指纹";
    
    // 判断设备是否支持指纹识别
    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
        if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"zhiwenshibie"]isEqualToString:[Finance_Tools getUserID]]) {
            // 指纹识别只判断当前用户是否机主
            [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                      localizedReason:myLocalizedReasonString
                                reply:^(BOOL success, NSError *error) {
                                    if (success) {
                                        // User authenticated successfully, take appropriate action
                                        NSLog(@"指纹认证成功");
                                        dispatch_async(dispatch_get_main_queue(), ^{

                                        [self createTiXianDownload:[[NSUserDefaults standardUserDefaults] objectForKey:@"PassWord"]];
                                        });                                     
                                    } else {
                                        NSLog(@"指纹认证失败,%@",error.description);
                               
                                        dispatch_async(dispatch_get_main_queue(), ^{
                                            
                                            //回到主线程操作代码块
                                            if ([[@(error.code) stringValue] isEqualToString:@"-2"]||[[@(error.code) stringValue] isEqualToString:@"-4"]) {
                                            }else if ([[@(error.code) stringValue] isEqualToString:@"-3"]||[[@(error.code) stringValue] isEqualToString:@"-8"]||[[@(error.code) stringValue] isEqualToString:@"-1"]){
                                                //失败原因,弹出弹框输入密码
                                                
                                            }
                                            
                                        });
                                        
                                        
                                    }
                                }];
            
        }else{
            //开启指纹识别
        }
    } else {
        // Could not evaluate policy; look at authError and present an appropriate message to user
        NSLog(@"TouchID设备不可用");
        // TouchID没有设置指纹
        // 关闭密码(系统如果没有设置密码TouchID无法启用)
        
//弹出弹框输入密码

}
}

失败原因:

NSLog(@"指纹认证失败,%@",error.description);
                                    // 错误码 error.code
                                    // -1: 连续三次指纹识别错误
                                    // -2: 在TouchID对话框中点击了取消按钮
                                    // -3: 在TouchID对话框中点击了输入密码按钮
                                    // -4: TouchID对话框被系统取消,例如按下Home或者电源键
                                    // -8: 连续五次指纹识别错误,TouchID功能被锁定,下一次需要输入系统密码

 

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!
技术狗 » iOS指纹识别