iOS 指纹验证
2016-06-30 18:21
453 查看
#import
<LocalAuthentication/LocalAuthentication.h>
/**
* 指纹验证
*/
- (void)authenticateUser {
//初始化上下文对象
LAContext* context = [[LAContext
alloc] init];
//错误对象
NSError* error =
nil;
NSString* result =
@"指纹验证";//Authentication is needed to access
your notes.
//首先使用canEvaluatePolicy
判断设备支持状态
if ([context
canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
error:&error]) {
//支持指纹验证
[context
evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:result
reply:^(BOOL success,
NSError *error) {
if (success) {
//验证成功,主线程处理UI
NSLog(@"//验证成功,主线程处理UI");
}else{
NSLog(@"%@",error.localizedDescription);
switch (error.code) {
case LAErrorSystemCancel:
{
// NSLog(@"Authentication was cancelled by the system");
//切换到其他APP,系统取消验证Touch ID
NSLog(@"切换到其他APP,系统取消验证Touch
ID");
break;
}
case LAErrorUserCancel:
{
// NSLog(@"Authentication was cancelled by the user");
NSLog(@"用户取消验证Touch IDD");
//用户取消验证Touch ID
break;
}
case LAErrorUserFallback:
{
NSLog(@"User selected to enter custom password");
[[NSOperationQueue
mainQueue] addOperationWithBlock:^{
NSLog(@"用户选择输入密码,切换主线程处理");
}];
break;
}
default:
{
[[NSOperationQueue
mainQueue] addOperationWithBlock:^{
NSLog(@"其他情况,切换主线程处理");
//其他情况,切换主线程处理
}];
break;
}
}
}
}];
}else{
//不支持指纹识别,LOG出错误详情
switch (error.code) {
case
LAErrorTouchIDNotEnrolled:
{
// TouchID is not enrolled
NSLog(@"TouchID
未注册");
break;
}
case
LAErrorPasscodeNotSet:
{
// A passcode has not been set
NSLog(@"没有设置密码");
break;
}
default:
{
// TouchID not available
NSLog(@"TouchID不可用");
break;
}
}
NSLog(@"%@",error.localizedDescription);
}
}
<LocalAuthentication/LocalAuthentication.h>
/**
* 指纹验证
*/
- (void)authenticateUser {
//初始化上下文对象
LAContext* context = [[LAContext
alloc] init];
//错误对象
NSError* error =
nil;
NSString* result =
@"指纹验证";//Authentication is needed to access
your notes.
//首先使用canEvaluatePolicy
判断设备支持状态
if ([context
canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
error:&error]) {
//支持指纹验证
[context
evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:result
reply:^(BOOL success,
NSError *error) {
if (success) {
//验证成功,主线程处理UI
NSLog(@"//验证成功,主线程处理UI");
}else{
NSLog(@"%@",error.localizedDescription);
switch (error.code) {
case LAErrorSystemCancel:
{
// NSLog(@"Authentication was cancelled by the system");
//切换到其他APP,系统取消验证Touch ID
NSLog(@"切换到其他APP,系统取消验证Touch
ID");
break;
}
case LAErrorUserCancel:
{
// NSLog(@"Authentication was cancelled by the user");
NSLog(@"用户取消验证Touch IDD");
//用户取消验证Touch ID
break;
}
case LAErrorUserFallback:
{
NSLog(@"User selected to enter custom password");
[[NSOperationQueue
mainQueue] addOperationWithBlock:^{
NSLog(@"用户选择输入密码,切换主线程处理");
}];
break;
}
default:
{
[[NSOperationQueue
mainQueue] addOperationWithBlock:^{
NSLog(@"其他情况,切换主线程处理");
//其他情况,切换主线程处理
}];
break;
}
}
}
}];
}else{
//不支持指纹识别,LOG出错误详情
switch (error.code) {
case
LAErrorTouchIDNotEnrolled:
{
// TouchID is not enrolled
NSLog(@"TouchID
未注册");
break;
}
case
LAErrorPasscodeNotSet:
{
// A passcode has not been set
NSLog(@"没有设置密码");
break;
}
default:
{
// TouchID not available
NSLog(@"TouchID不可用");
break;
}
}
NSLog(@"%@",error.localizedDescription);
}
}
相关文章推荐
- iOS向上滑动,导航栏颜色逐渐加深
- 判断苹果各种智能手机设备型号
- IOS CollectionView 线性布局
- 清理iOS工程里无用的图片,可瘦身ipa
- IOS-autolayout
- IOS 永久保存相册或相机拍照的图片
- iOS开发调试技巧(一)
- IOS开发之按钮控件Button详解
- ios中修改状态栏颜色的方法
- ios 跨页返回,从navigationController 删除指定页面
- iOS 开发 单例的写法
- iOS-CollectionView 瀑布流视图
- [iOS 禁用第三方输入法] 禁用第三方输入法+ExtensionPointIdentifier理解
- iOS 地图源及目的地定位、划线和系统导航的使用
- iOS开发 正则表达式
- ios开发解决遍历删除数组对象报错
- iOS 通过网址URL scheme传值
- NSMutableAttributedString属性文字
- ios pod库更新到1.0或1.0.1之正确修改podfile文件
- iOS中URL Scheme是干嘛的