首页 > 代码库 > 如何使用iOS 8 指纹识别,代码,例子
如何使用iOS 8 指纹识别,代码,例子
跟想象的一样,iOS 8中的指纹识别使用起来还是很方便的,只需要一个接口就能搞定,屏幕上弹出一个模态的框,跟app store上的一样。
直接上代码吧,下面代码拷贝自Apple的官方文档。
需要添加LocalAuthentication.framework库,注意只有真机才有这个库,模拟器没有
#import "LocalAuthentication/LAContext.h" LAContext *myContext = [[LAContext alloc] init]; NSError *authError = nil; NSString *myLocalizedReasonString = @"请输入指纹"; if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString reply:^(BOOL success, NSError *error) { if (success) { // User authenticated successfully, take appropriate action } else { // User did not authenticate successfully, look at error and take appropriate action } }]; } else { // Could not evaluate policy; look at authError and present an appropriate message to user }
效果如图所示:MyAddressBook 是我的app名字,“请输入指纹”是代码中的字符串
还是很简单的。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。