iOS8 Touch ID api接口调用
来源:互联网 发布:新浪首页软件下载 编辑:程序博客网 时间:2024/05/17 01:45
Touch ID简介
Touch ID是苹果公司提供的一种将指纹用作密码的简便方式。只需轻触i主屏幕按钮,就能激活Touch ID传感器。主屏幕按钮周围的钢圈检测手指通知 Touch ID读取指纹。Touch ID 不会储存指纹的任何图像。它只存储指纹的数学表达式。
Touch ID的指纹数据存储在A7处理器的一个叫"secure enclave"协处理器上,唯一的Touch ID指纹识别器与唯一单独的A7处理器匹配。也就是说你将Touch ID拆开装到别的iPhone 5s上,Touch ID是无法使用的,因为它无法读取到A7处理器上的指纹数据。
Touch ID接口
使用Touch ID需要导入LocalAuthentication.framework,必须在装有iOS8的真机设备才能编译通过。
导入
- #import <LocalAuthentication/LAContext.h>
判断当前是否有可用的Touch ID
- (BOOL)canEvaluatePolicy { LAContext *context = [[LAContext alloc] init]; NSError *error; BOOL success; // test if we can evaluate the policy, this test will tell us if Touch ID is available and enrolled success = [context canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]; return success; }
判断[context canEvaluatePolicy:error:];判断当前是否有可用Touch ID,设备没有设备没有TouchID或者TouchID未开启返回false,有TouchID并开启返回true.
调用显示验证界面
- (void)evaluatePolicy { LAContext *context = [[LAContext alloc] init]; __block NSString *msg; // show the authentication UI with our reason string [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"UNLOCK_ACCESS_TO_LOCKED_FATURE", nil) reply: ^(BOOL success, NSError *authenticationError) { if (success) { msg =[NSString stringWithFormat:@"EVALUATE_POLICY_SUCCESS"]; } else { msg = [NSString stringWithFormat:@"EVALUATE_POLICY_WITH_ERROR : %@", authenticationError]; } UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:msg message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; [alertView show]; }]; }
调用[contextevaluatePolicy:localizedReason:reply]可以显示验证界面,验证完毕后有一个回调。苹果官方文档规定第二个参数localizedReason一定要(shoudbe)使用用户的当前语言呈现。
真机演示(演示指纹识别成功的例子)
测试用的代码片段
- (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[UIColor whiteColor]]; UIButton* btn = [[UIButton alloc] init]; [btn setTitle:@"push me!" forState:UIControlStateNormal]; CGRect frame = CGRectMake(self.view.frame.size.width/2 - 60., self.view.frame.size.height/2, 120., 80.); [btn setFrame:frame]; [btn addTarget:self action:@selector(showTouchId) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } - (void)showTouchId { if ([self canEvaluatePolicy]) { [self evaluatePolicy]; } else { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"5s ok?" message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; [alertView show]; } } #pragma mark - Tests - (BOOL)canEvaluatePolicy { LAContext *context = [[LAContext alloc] init]; NSError *error; BOOL success; // test if we can evaluate the policy, this test will tell us if Touch ID is available and enrolled success = [context canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]; return success; } - (void)evaluatePolicy { LAContext *context = [[LAContext alloc] init]; __block NSString *msg; // show the authentication UI with our reason string [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"UNLOCK_ACCESS_TO_LOCKED_FATURE", nil) reply: ^(BOOL success, NSError *authenticationError) { if (success) { msg =[NSString stringWithFormat:@"EVALUATE_POLICY_SUCCESS"]; } else { msg = [NSString stringWithFormat:@"EVALUATE_POLICY_WITH_ERROR : %@", authenticationError]; } UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:msg message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; [alertView show]; }]; }
0 0
- iOS8 Touch ID api接口调用
- iOS8 Touch ID api接口调用
- iOS8 touch id
- IOS8 指纹解锁 Touch ID
- Touch ID指纹识别功能 iOS8
- 关于ios8之后touch Id的问题
- Swift下调用Touch ID实现指纹识别
- 关于接口api调用
- 调用地图api接口
- Touch ID
- Touch ID
- iOS8 API
- 在iOS 8 SDK中使用Touch ID API(下)
- 在iOS 8 SDK中使用Touch ID API
- 在iOS 8 SDK中使用Touch ID API
- C++调用Lua API接口
- PHP如何调用API接口
- C++调用Lua API接口
- HDU 4012 Paint on a Wall(BFS+位压缩)(好题)(初遇位压缩)
- LoadRunner下载地址及破解方法
- Android 之使用LocalBroadcastManager,源码解析
- CSS3 Region:基于HTML和CSS3的富页面布局
- 将截断字符串或二进制数据. 语句已终止
- iOS8 Touch ID api接口调用
- PHP判断日期格式
- c++的代码、变量在内存中的存放位置
- Linux多命令执行符
- android gps
- 使用python的requests 发送multipart/form-data 请求
- 使用路径(Path)工具时的几个技巧
- 一个研究生毕业后的职业规划 -----我今年39岁了,25岁研究生毕业,工作14年,回头看看,应该说走了不少的弯路,有一些经验和教训。
- 如何判断一个exe为64位