如何查看 TouchID 启用与否

How to check TouchID enable or not

有什么方法可以检查我的应用程序是否启用了 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)

然后,用LAContextcanEvaluatePolicy: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 版本,当然,它可能有效,但这是一种不好的做法。而是检查该功能。查看 LAContext 是否可用。

if ([LAContext class]) {
    // touch ID is available for the device
    // call canEvaluatePolicy:error to see if the user has set a fingerprint.
}

假设 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) {