iOS 开发系列之在应用中添加TouchID 验证身份
来源:互联网 发布:淘宝网我要买 编辑:程序博客网 时间:2024/05/22 05:32
iOS 8 SDK公开了Touch ID指纹识别功能,允许APP能够在自己的应用中通过指纹识别功能进行身份验证,指纹识别的依赖库是LocalAuthentication framework, 如果应用中需要身份验证的话,首先需要导入LocalAuthentication framework。
以下是一个demo ,通过button的点击事件来验证指纹密码
1.在storyboard拖放button,并设置点击事件
2.在项目中引入LocalAuthentication framework
3.在类中 引入 头文件LocalAuthentication.h
4.button的点击事件
- (IBAction)touchIdAction:(id)sender {
LAContext *context = [LAContext new];
NSError *error;
//当指纹识别错误时,让再试一次,alert右边按钮的title,默认情况下是“enter the password”,如果设置为空的话就不显示,左边按钮是取消
context.localizedFallbackTitle = @"输入登录密码";
//canEvaluatePolicy 返回值Bool,用来判断设备是否支持Touch ID
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
NSLog(@"canEvaluatePolicy设备支持Touch ID");
//evaluatePolicy 验证Touch ID
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"通过Home键验证已有手机指纹", nil) reply:^(BOOL success, NSError * _Nullable error) {
NSLog(@"evaluetePlolicy");
if (success) {
NSLog(@"evaluatePolicy success TouchID验证成功");
//验证成功后续操作
} else {
NSLog(@"evaluatePolicy failure TouchID验证失败");
if (error.code == kLAErrorUserFallback) {
NSLog(@"error user fall back");
} else if (error.code == kLAErrorUserCancel) {
NSLog(@"error user cancel");
} else {
NSLog(@"Authenticated fail");
}
}
}];
} else {
NSLog(@"can not evaluatePolicy设备不支持TouchID");
}
}
5.验证失败的error code有以下几种情况,在不同的情况下回调
error.code == kLAErrorUserFallback 在第一次指纹失败,让在试一次时alert会有两个按钮,取消或者是上边定义的context.localizedFallbackTitle,如果点击alert右边的按钮会进入这个if分支
error.code == kLAErrorUserCancel 用户点击取消按钮
kLAErrorAuthenticationFailed 连续三次指纹错误
kLAErrorSystemCancel 在Touch ID对话框的显示过程中,被系统取消
kLAErrorPasscodeNotSet
kLAErrorTouchIDNotAvailable
kLAErrorTouchIDNotEnrolled
kLAErrorTouchIDLockout
kLAErrorAppCancel
kLAErrorInvalidContext
- iOS 开发系列之在应用中添加TouchID 验证身份
- iOS开发之TouchId
- iOS TouchID指纹验证
- iOS应用TouchID解锁
- iOS学习笔记02-指纹验证TouchID简单应用1
- iOS学习笔记03-指纹验证TouchID简单应用2
- iOS开发--touchID指纹识别
- iOS TouchID验证和Keychain结合使用
- iOS开发实现TouchID指纹解锁
- iOS开发实现TouchID指纹解锁
- iOS开发实现TouchID指纹解锁
- iOS开发实现TouchID指纹解锁
- iOS 指纹认证登陆开发(TouchID)
- ios touchid
- iOS TouchID
- ios TouchId
- Block如何在ios开发中应用
- ios开发之在iOS应用中加载自定义字体显示
- Lighttpd中CGI执行流程
- 关于sizeof的面试题,回答很好地解释了sizeof的相关特性
- selector.xml无效的解决办法
- JavaScript日期集合(今日,昨日,本周一,周末 ,月初,月末)
- 关于内存管理的笔记
- iOS 开发系列之在应用中添加TouchID 验证身份
- 内容提供者ContentProvider的基本使用
- 明明的随机数
- django modeladmin override ModelForm
- object-c 单例模式的线程安全
- 在Delphi中利用MSDASC来配置数据库链接
- 非常简单的几行代码实现炫酷的tableview cell动画
- noty – jQuery通知插件
- ArcGIS教程:时态数据管理和可视化快速浏览