Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If Device Supports Touch ID

Wondering how I can determine if the device the user has supports the Touch ID API? Hopefully have this as a boolean value.

Thanks!

like image 667
Harry Avatar asked Dec 08 '22 05:12

Harry


2 Answers

try this:

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

or like @rckoenes suggest:

- (BOOL)canAuthenticateByTouchId {
    if ([LAContext class]) {
        return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
    }
    return NO;
}

UPDATE

I forgot, check this: How can we programmatically detect which iOS version is device running on? to define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO

like image 164
Mateusz Avatar answered Dec 10 '22 17:12

Mateusz


You should consider LAContext framework that is required to Touch ID authentication.

And parameter LAErrorTouchIDNotAvailable will show is devise support this functionality.

Code snippet :

- (IBAction)authenticateButtonTapped:(id)sender {
    LAContext *context = [[LAContext alloc] init];

    NSError *error = nil;

    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
        // Authenticate User

    } else {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                        message:@"Your device cannot authenticate using TouchID."
                                                       delegate:nil
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];
        [alert show];

    }
}

Nice tutorial to learn this feature is here.

like image 33
Oleg Gordiichuk Avatar answered Dec 10 '22 18:12

Oleg Gordiichuk