touch id简介:
苹果公司在iphone 5s手机中推出了指纹识别功能,提高手机安全性的同时也方便了用户操作。其功能是通过touch id实现的,从ios 8系统开始,苹果开发一些touch id的api使得开发人员可以在自己的应用程序中调用指纹识别功能。
touch id功能就是指纹识别密码。使用指纹识别功能需要先进入设置—touch id 与密码中根据提示添加指纹。
从ios 8系统开始开放了touch id的验证接口功能,在应用程序中可以判断输入的touch id是否设置持有者的touch id。
touch id使用:
创建一个ios工程项目。
打开工程的general — linked frameworks and libraries面板,单机“+”按钮添加“localauthentication.framework”框架,如图26-1所示。
编写程序时导入“localauthentication.framework”框架的头文件:
#import <localauthentication/localauthentication.h>。
写了一个简单的测试touch id的例子,效果图如下:(若图片不清楚可右键将图片保存本地再放大看)
下面贴上代码:
#import <uikit/uikit.h> @interface hwtouchidtestvc : uiviewcontroller @end #import "hwtouchidtestvc.h" #import <localauthentication/localauthentication.h> @interface hwtouchidtestvc () @property (nonatomic, weak) uilabel *label; @end @implementation hwtouchidtestvc - (void)viewdidload { [super viewdidload]; self.view.backgroundcolor = [uicolor blackcolor]; //创建控件 [self creatcontrol]; } - (void)creatcontrol { //测试按钮 uibutton *btn = [[uibutton alloc] initwithframe:cgrectmake(50, 200, 120, 50)]; btn.backgroundcolor = [uicolor orangecolor]; [btn settitle:@"测试按钮" forstate:uicontrolstatenormal]; [btn addtarget:self action:@selector(btnonclick) forcontrolevents:uicontroleventtouchupinside]; [self.view addsubview:btn]; //提示标签 uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(220, 200, 120, 50)]; label.text = @"测试标签"; label.textalignment = nstextalignmentcenter; label.backgroundcolor = [uicolor yellowcolor]; [self.view addsubview:label]; self.label = label; } - (void)btnonclick { //初始化 lacontext *context = [[lacontext alloc] init]; nserror *error = nil; //显示的文字 nsstring *str = @"指纹验证"; //判断是否能进行验证 if ([context canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics error:&error]) { [context evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics localizedreason:str reply:^(bool success, nserror * _nullable error) { if (success) { nslog(@"验证成功"); dispatch_async(dispatch_get_main_queue(), ^{ self.label.text = @"验证成功"; self.label.backgroundcolor = [uicolor greencolor]; }); }else { nslog(@"验证失败,error:%@", error); dispatch_async(dispatch_get_main_queue(), ^{ self.label.text = @"验证失败"; self.label.backgroundcolor = [uicolor redcolor]; }); } }]; }else { nslog(@"无法验证指纹,error: %@", error); self.label.text = @"无法验证"; } } @end
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
APP调用微信小程序,能拉起小程序,但是onResp回调不会被调用问题
Codeforces Round #657 (Div. 2) B. Dubious Cyrpto(思维,数学)
网友评论