指纹登录

判断是否支持指纹识别:

 // 判断设备是否支持指纹识别
    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;
    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
        datas = @[@[@"账号绑定",@"修改密码",@"指纹登录"],@"关于我们"],@[@"退出当前账号"]];
    }else{
        datas = @[@[@"账号绑定",@"修改密码"],@"关于我们"],@[@"退出当前账号"]];
    }

判断当前用户是否是机主:

-(void)loginWithFingerprint{
    LAContext *myContext = [[LAContext alloc] init];
    NSString *myLocalizedReasonString = @"请进行指纹登录";
    myContext.localizedFallbackTitle=@"";
    myContext.maxBiometryFailures = @(3);
    
    // 指纹识别只判断当前用户是否机主
    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
              localizedReason:myLocalizedReasonString
                        reply:^(BOOL success, NSError *error) {
                            if (success) {
                                // User authenticated successfully, take appropriate action
                                NSLog(@"指纹认证成功");
                                
                                // 请求数据,获取登录标识符
                                [User userSignInWithFingerprint:@{@"fingerprint":[[NSUserDefaults standardUserDefaults] objectForKey:@"loginID"]} showHUD:YES parentViewController:self success:^(id data) {
                                    [GlobalKit sharedKit].bestUser = data;
                                    [[NSNotificationCenter defaultCenter] postNotificationName:BESTUserSignInSuccessNotification object:nil];
                                    [self dismissViewControllerAnimated:YES completion:NULL];
                                } failure:^(NSError *error, NSString *message) {
                                    
                                }];
                                
                            } else {
                                // User did not authenticate successfully, look at error and take appropriate action
                                NSLog(@"指纹认证失败,%@",error.description);
                                
                                if (error.code == -1) {
                                    [[[UIAlertView alloc] initWithTitle:@"提示" message:@"您已连续三次指纹识别错误,请使用其他方式登录吧~" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil] show];
                                }
                                // 错误码 error.code
                                // -1: 连续三次指纹识别错误
                                // -2: 在TouchID对话框中点击了取消按钮
                                // -3: 在TouchID对话框中点击了输入密码按钮
                                // -4: TouchID对话框被系统取消,例如按下Home或者电源键
                                // -8: 连续五次指纹识别错误,TouchID功能被锁定,下一次需要输入系统密码
                                
                                //                                            returnCode = [@(error.code) stringValue];
                                //                                            [self dismissViewControllerAnimated:YES completion:nil];
                            }
                        }];
}

错误码使用方法:

if (error.code == kLAErrorAuthenticationFailed) {//-1
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        [[[UIAlertView alloc] initWithTitle:@"提示" message:@"已连续三次指纹识别错误,您可以尝试使用其他方式登录哦~" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil] show];
    }];
}
if (error.code == kLAErrorTouchIDLockout) {//-8
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        [[[UIAlertView alloc] initWithTitle:@"注意" message:@"已连续五次指纹识别错误,TouchID功能被锁定,下一次需要输入系统密码,以解除锁定" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil] show];
    }];
}

附注:

http://www.cnblogs.com/jager/p/5241012.html
https://blog.csdn.net/pucker/article/details/43410585

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容