How to check TouchID enable or not

2019-05-15 02:20发布

Is there any way to check my application is enable with TouchID,

How can i check if my application is enable with TouchID,

For example :

DropBox have capability to enable figure print sensor enable. now is there any method to check if my application showing TouchID screen based on touchid enable.

3条回答
欢心
2楼-- · 2019-05-15 02:57

According you use Objective-C

First, add method to check iOS Version

TouchID needs iOS8+ to work

#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)

Then, use LAContext canEvaluatePolicy:error: to evaluate if TouchID exist

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;
}
查看更多
姐就是有狂的资本
3楼-- · 2019-05-15 03:12

assuming ios 8+ deployment target

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

in case you still need to support ios7 do the extra hoop

   if NSClassFromString("LAContext") != nil && LAContext().canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &authError) {
查看更多
成全新的幸福
4楼-- · 2019-05-15 03:23

You do not want to check the iOS version, sure, it might work but it is a bad practice. Check for the feature instead. See if LAContext is available.

if ([LAContext class]) {
    // touch ID is available for the device
    // call canEvaluatePolicy:error to see if the user has set a fingerprint.
}
查看更多
登录 后发表回答