Search code examples
iosiphonetouch-id

How to check TouchID enable or not


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.


Solution

  • 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;
    }