ios – 如何检查TouchID是否启用

有没有办法检查我的应用程序启用TouchID,

如何检查我的应用程序是否启用了TouchID,

例如 :

DropBox具有启用图形打印传感器功能的功能.现在有什么方法可以检查我的应用程序是否显示基于touchid启用的TouchID屏幕.

最佳答案
根据你使用Objective-C

首先,添加方法来检查iOS版本

TouchID需要iOS8才能运行

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

然后,使用LAContext canEvaluatePolicy:error:来评估TouchID是否存在

Preflights an authentication policy to see if it is possible for authentication to succeed

- (BOOL)isTouchIDAvailable {
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
        return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
    }
    return NO;
}

转载注明原文:ios – 如何检查TouchID是否启用 - 代码日志