首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检测没有可用设备的指纹传感器

如何检测没有可用设备的指纹传感器
EN

Stack Overflow用户
提问于 2017-02-03 07:37:18
回答 2查看 1.6K关注 0票数 2

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

请帮帮我。谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-02-03 07:49:14

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

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

代码片段:

代码语言:javascript
复制
- (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返回:

代码语言:javascript
复制
- (BOOL)canAuthenticateByTouchId {
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
    return [[[LAContext alloc] init] canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
    }
    return NO;
}
票数 1
EN

Stack Overflow用户

发布于 2017-09-12 06:53:36

代码语言:javascript
复制
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
}
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42019069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档