iOS中指纹识别常见问题汇总

2020-01-18 18:25:41刘景俊

ios10,指纹识别


[SVProgressHUD show];
LAContext *context = [[LAContext alloc]init];//使用 new 不会给一些属性初始化赋值
context.localizedFallbackTitle = @"";//这样可以不让 feedBack 按钮显示
//LAPolicyDeviceOwnerAuthenticationWithBiometrics
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"请验证已有指纹" reply:^(BOOL success, NSError * _Nullable error) {
[SVProgressHUD dismiss];
//SVProgressHUD dismiss 需要 0.15才会消失;所以dismiss 后进行下一步操作;但是0.3是适当延长时间;留点余量
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (success)
{
NSLog(@"指纹识别成功");
// 指纹识别成功,回主线程更新UI
dispatch_async(dispatch_get_main_queue(), ^{
//成功操作
});
}
if (error) {
//指纹识别失败,回主线程更新UI
NSLog(@"指纹识别成功");
dispatch_async(dispatch_get_main_queue(), ^{
//失败操作
});
}
});
}];

7.弹窗显示级别问题

指纹识别的弹窗的级别非常之高,高到离谱,经过验证应用程序内部没有比指纹识别的window的级别更高的UIWindowLevel,也就说了他是系统级的弹窗。需要注意的是,如果指纹弹窗显示和消失应用程序会调用:


- (void)applicationWillResignActive:(UIApplication *)application;
- (void)applicationDidBecomeActive:(UIApplication *)application;

所以应用程序内部无法获取。不知道越狱之后的手机能否获取到,如果能获取到,那就不可描述了,所以推荐各位看官没什么刚需不要越狱。

8.检测指纹库中指纹是否发生改变

苹果官方文档解释如下

This property returns a value only when the canEvaluatePolicy(:error:) method succeeds for a biometric policy or the evaluatePolicy(:localizedReason:reply:) method is called and a successful Touch ID authentication is performed. Otherwise, nil is returned.
The returned data is an opaque structure. It can be used to compare with other values returned by this property to determine whether the database of authorized fingerprints has been updated. However, the nature of the change cannot be determined from this data.

总结来说:

当你增加或者删除指纹时候,你在使用使用canEvaluatePolicy(_:error:)或者evaluatePolicy(_:localizedReason:reply:)方法验证;成功后evaluatedPolicyDomainState属性会返回一个 NSData 对象;否则返回 nil;
但是返回的evaluatedPolicyDomainState属性并不能说明发生了什么样子的改变;只是告诉你发生了改变

根据上面的信息,我们就可以每次使用指纹的时候检测指纹数据库是否发生改变并作出相应的操作;下面是stackOverFlow 做的一个相应示例