TouchID 的校验方式:
LAPolicyDeviceOwnerAuthenticationWithBiometrics:指纹验证。首次启动有三次验证的机会,失败后TouchID校验的弹框会消失。再次启动有两次机会,如果还失败,TouchID就会被锁定,后面再启动程序TouchID就不会在弹出。这里我们需要用下面一种校验方式来解除TouchID的锁定
LAPolicyDeviceOwnerAuthentication:指纹验证+系统密码验证。如果TouchID正常录入则优先使用TouchID,如果出现上面那种情况,TouchID被锁定,就需要用系统密码校验来解除锁定哪个。
其他概念不在详述,面向搜索引擎查询
下面代码区
LAContext *lol = [[[LAContext alloc] init]autorelease];
NSError *error = nil;
NSString *tempStr = NSLocalizedString(@"解锁", nil);
//TODO:TOUCHID是否存在
if ([lol canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
//TODO:TOUCHID开始运作
[lol evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:tempStr reply:^(BOOL succes, NSError *error)
{
if (succes) {
//do something when your TouchID verify success
}
else
{
}
}];
}
else
{
switch (error.code) {
case -5:
NSLog(@"---- kLAErrorPasscodeNotSet (未设置密码)");
break;
case -6:
NSLog(@"---- kLAErrorTouchIDNotAvailable (设备不支持)");
break;
case -7:
NSLog(@"---- kLAErrorTouchIDNotEnrolled (Touch ID没有注册的手指。)");
// error = Error Domain=com.apple.LocalAuthentication Code=-7 "No fingers are enrolled with Touch ID." UserInfo={NSLocalizedDescription=No fingers are enrolled with Touch ID.}------- (模拟器测试 或 真机设备未设置手指)
break;
case -8:
NSLog(@"---- kLAErrorTouchIDLockout (Touch ID 功能被锁定)");
//错误信息:error = Error Domain=com.apple.LocalAuthentication Code=-8 "Biometry is locked out." UserInfo={NSLocalizedDescription=Biometry is locked out.}------- (Touch ID 被锁)
//连续输入错误后 TouchID被锁定,当再次启动程序时,不会弹出验证指纹,而是进入本case,在这里我们要通过输入系统密码来解除TouchID的锁定
//LAPolicyDeviceOwnerAuthentication 后面详说
[lol evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:@"解除Touch ID锁定" reply:^(BOOL success, NSError * _Nullable error){
if (success) {
[self showTouchID];
}
}];
break;
default:
break;
}
NSLog(@"------ Touch ID不可用 error = %@-------", error);
}
}
网友评论