您的位置:首页 > 移动开发 > IOS开发

Touch ID指纹识别功能 iOS8

2015-12-20 13:56 531 查看
- (IBAction)loginAction:(id)sender {

NSLog(@"登录触发方法");
// 步骤一 检查Touch ID是否可用
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"通过Home键验证已有手机指纹";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
NSLog(@"Touch ID可以使用");

[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
// 成功
NSLog(@"成功");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SuccessViewController *successVC = [storyboard instantiateViewControllerWithIdentifier:@"SuccessViewController"];
[self.navigationController pushViewController:successVC animated:YES];

} else {

// 获取到相应的错误信息····做相应的操作
// 失败
NSLog(@"%@", error); // 错误信息

NSString *domin = [error domain]; //获取错误域  一般
NSLog(@"%@", domin);
NSDictionary *userInfo = [error userInfo]; //错误详细信息
NSLog(@"%@", userInfo);

NSInteger code = [error code]; // 获取Code值  一般domin 和 code 一起就是一个错误信息
if (code == -3) {
// 点击了手指密码的 输入密码按钮
NSLog(@"点击了手指密码的 输入密码按钮");

}

if (code == -2) {
NSLog(@"点击了手指密码的取消按钮");
}

if (code == -1) {
NSLog(@"指纹密码不可用, 重新输入指纹密码");
}
}
}];

}else {
//
NSLog(@"Touch ID 不可用");
}
}


demo下载地址:

http://download.csdn.net/detail/yj229201093/9369022

参考链接

/article/2260271.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: