如何检测指纹传感器不可用的设备

How to detect finger print sensor not available device

我在我的 iOS 应用中启用了触控 ID。但是 iPhone 5 和 5c 指纹传感器不可用。如何以编程方式检测没有指纹传感器的设备。我的应用程序是用 objective-c.

编写的

请帮帮我。 谢谢

您应该使用 Touch ID 身份验证所需的 LAContext 框架。

LAErrorTouchIDNotAvailable 显示哪个设备具有该功能。

代码片段:

- (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];

    }
}    

或尝试使用此方法获取 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
}
}