【问题标题】:How to detect finger print sensor not available device如何检测指纹传感器不可用的设备
【发布时间】:2017-02-03 07:37:18
【问题描述】:

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

请帮助我。 谢谢

【问题讨论】:

标签: ios objective-c fingerprint touch-id


【解决方案1】:

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

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

代码 sn-p:

- (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 返回:

- (BOOL)canAuthenticateByTouchId {
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
    return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
    }
    return NO;
}

【讨论】:

  • 非常感谢。如果设备有触摸 ID 传感器并且用户没有设置触摸 ID 怎么办?我没有收到任何错误消息。我怎样才能检测到这一点?
  • the-nerd.be/2015/10/01/authentication-with-touchid 勾选此项以设置 Touch ID 非常简单。如果您喜欢我的回答,请投票。谢谢
【解决方案2】:
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
}
}

【讨论】:

  • 请尝试解释这段代码的作用以及它如何解决文本部分中 Q 的问题。
  • 我猜这个人在问如何检查是否存在指纹传感器。我认为他想区分存在指纹传感器和存在指纹传感器但未添加指纹。
  • edit为您的答案提供解释性文字。因此,未来的用户将能够遵循并理解您的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-15
  • 1970-01-01
  • 1970-01-01
  • 2011-02-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多