2

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

user1960169
  • 3,533
  • 12
  • 39
  • 61
  • http://stackoverflow.com/questions/11197509/ios-how-to-get-device-make-and-model. Use this to find the model of the device. – Sachin Vas Feb 03 '17 at 07:54

2 Answers2

1

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;
}
Ankit Kumar Gupta
  • 3,994
  • 4
  • 31
  • 54
  • 2
    Thank you so much. What if the device has touch ID sensor and user has not setup the touch ID. im not getting any error message for that. How can I detect this? – user1960169 Feb 03 '17 at 08:04
  • 1
    https://the-nerd.be/2015/10/01/authentication-with-touchid/ Check this for setting up Touch ID really very simple. Up vote if you like my answer. Thanks – Ankit Kumar Gupta Feb 03 '17 at 08:37
0
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
}
}
loki
  • 9,816
  • 7
  • 56
  • 82
  • please try to explain what this code does and how this solves the problem from the Q in a text section. – loki Sep 12 '17 at 07:20
  • I guess the person was asking how to check whether finger print sensors are present. I think he wanted to differentiate between fingerprint sensors present and finger print sensors present but no finger prints added. – Angshuk Nag Sep 12 '17 at 07:30
  • Please [edit](https://stackoverflow.com/posts/46169804/edit) an explanatory text to your answer. Thus, future users will be able to follow and understand your approach. – loki Sep 12 '17 at 08:18