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?
The method you are looking for is LAContext
's canEvaluatePolicy:error:
.
It will return NO in the following cases :
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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With