3

有什么方法可以检查我的应用程序是否启用了 TouchID,

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

例如 :

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

4

3 回答 3

6

您不想检查 iOS 版本,当然,它可能有效,但这是一种不好的做法。而是检查该功能。查看 LAContext 是否可用。

if ([LAContext class]) {
    // touch ID is available for the device
    // call canEvaluatePolicy:error to see if the user has set a fingerprint.
}
于 2015-04-10T10:07:41.463 回答
5

根据你使用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存在

预检身份验证策略以查看身份验证是否可能成功

- (BOOL)isTouchIDAvailable {
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
        return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
    }
    return NO;
}
于 2015-04-10T08:44:25.210 回答
1

假设 ios 8+ 部署目标

    var authError : NSError?
    if LAContext().canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &authError) {
          // do your thing dependent on touch id being useable on the device
    }

如果你仍然需要支持 ios7 做额外的箍

   if NSClassFromString("LAContext") != nil && LAContext().canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &authError) {
于 2016-04-13T07:57:29.530 回答