I have enabled touch id inmy iOS app. But iPhone 5 and 5c the finger print sensor is not available. How can I detect devices programmatically which are not having finger print sensor. My app is written in objective-c.
Please help me. Thanks
I have enabled touch id inmy iOS app. But iPhone 5 and 5c the finger print sensor is not available. How can I detect devices programmatically which are not having finger print sensor. My app is written in objective-c.
Please help me. Thanks
You should use LAContext framework that is required for Touch ID authentication.
LAErrorTouchIDNotAvailable shows which device has the functionality.
Code snippet :
- (IBAction)shouldAuthenticate:(id)sender {
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
// Authentication here.
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Your device cannot authenticate using TouchID."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
}
or try this to get BOOL return :
- (BOOL)canAuthenticateByTouchId {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
}
return NO;
}
func checkIfTouchIDEnabled() {
var error:NSError?
// 2. Check if the device has a fingerprint sensor
// If not, show the user an alert view and bail out!
guard authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
if let error = error as NSError? {
if error.code == LAError.Code.touchIDNotAvailable.rawValue { /* Device does not support touch id*/
print("Finger print sensors are not present in this device")
} else if error.code == LAError.Code.touchIDNotEnrolled.rawValue {
print("Finger print sensors are present in this device but no TouchID has been enrolled yet")
} else {
// Add more checks ...
}
}
return
}
}