Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See if Touch ID is enabled on iPhone 5s

Tags:

ios

ios7

touch-id

I know the Touch ID on the iPhone 5S cannot be consumed by any other apps through the SDK, but I wanted to see if it was possible for an app to at least see if the Touch ID is enabled on the device. This can act as an additional security factor for an app to see if the Touch ID has been enabled on an iPhone 5S. I know MDM products can do this, is there a special API an app would need to use to determine this information?

like image 608
ashkash Avatar asked Dec 21 '22 00:12

ashkash


2 Answers

The method you are looking for is LAContext's canEvaluatePolicy:error:. It will return NO in the following cases :

  • Touch ID is not available on the device.
  • A passcode is not set on the device.
  • Touch ID has no enrolled fingers.

More infos here : Local Authentication Framework Reference

- (BOOL) isTouchIDAvailable {
    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;

    if (![myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {

        NSLog(@"%@", [authError localizedDescription]);
        return NO;
    }
    return YES;
}
like image 140
ndethore Avatar answered Dec 24 '22 10:12

ndethore


Since TouchID is only appeared in iPhone 5s, you can use the following code to determine hardware model:

- (NSString *) checkiPhone5s {
  // Gets a string with the device model
  size_t size;  
  sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
  char *machine = malloc(size);  
  sysctlbyname("hw.machine", machine, &size, NULL, 0);  
  NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];  
  free(machine); 

  if ([platform isEqualToString:@"iPhone6,1"]) {
     // it is iPhone 5s !!!
  }
}

Note that iPhone 5s may have new model, so that the platform string may be "iPhone6,2" , "iPhone6,3" in the future.

Alternatively, UIDeviceHardware class may provide useful information if that class is updated for iPhone 5s. Currently it shows "Unknown iPhone" for iPhone 5.

like image 29
Raptor Avatar answered Dec 24 '22 11:12

Raptor