iOS8之后苹果发布了指纹识别的功能,通过touch ID来识别用户,做用户授权,主要是依赖于LocalAuthentication库
指纹识别:一判断设备是否支持指纹识别功能
二识别指纹,成功后做相应的动作,失败后提醒用户指纹识别失败
先引入#import <LocalAuthentication/LocalAuthentication.h>
LAContext *context = [[LAContext alloc] init]; NSError *error = nil; //验证是否支持指纹识别 if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { NSLog(@"支持指纹识别的应用"); //验证身份 [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"需要指纹来验证你的身份", @"hello") reply:^(BOOL success, NSError *error) { if (success) { NSLog(@"成功"); } else { switch (error.code) { case LAErrorUserCancel: NSLog(@"用户取消了授权 - %@", error.localizedDescription); break; case LAErrorUserFallback: NSLog(@"用户点击了“输入密码”按钮 - %@", error.localizedDescription); break; case LAErrorAuthenticationFailed: NSLog(@"您已授权失败3次 - %@", error.localizedDescription); break; case LAErrorTouchIDLockout: NSLog(@"指纹被锁定 - %@", error.localizedDescription); break; case LAErrorSystemCancel: NSLog(@"应用程序进入后台 - %@", error.localizedDescription); break; default: NSLog(@"++%@--%zd", error.localizedDescription, error.code); break; } } }]; } else { switch (error.code) { case LAErrorPasscodeNotSet: NSLog(@"未设置密码 - %@", error.localizedDescription); break; case LAErrorTouchIDNotEnrolled: NSLog(@"未注册 Touch ID - %@", error.localizedDescription); break; case kLAErrorTouchIDNotAvailable: NSLog(@"该设备不支持 Touch ID - %@", error.localizedDescription); break; default: NSLog(@"--%@--%zd", error.localizedDescription, error.code); break; } }
新闻热点
疑难解答