ios - 没有iPhone 5s设备时如何测试Touch ID功能

标签 ios touch-id

我想在应用程序中实现触摸ID功能,为此我编写了代码:

LAContext *context = [[LAContext alloc] init];

        NSError *error = nil;
        if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
            [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                    localizedReason:@"Are you the device owner?"
                              reply:^(BOOL success, NSError *error) {

                                  if (error) {
                                      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                                      message:@"There was a problem verifying your identity."
                                                                                     delegate:nil
                                                                            cancelButtonTitle:@"Ok"
                                                                            otherButtonTitles:nil];
                                      [alert show];
                                      return;
                                  }

                                  if (success) {
                                      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                                                                      message:@"You are the device owner!"
                                                                                     delegate:nil
                                                                            cancelButtonTitle:@"Ok"
                                                                            otherButtonTitles:nil];
                                      [alert show];

                                  } else {
                                      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                                      message:@"You are not the device owner."
                                                                                     delegate:nil
                                                                            cancelButtonTitle:@"Ok"
                                                                            otherButtonTitles:nil];
                                      [alert show];
                                  }

                              }];

        } else {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                            message:@"Your device cannot authenticate using TouchID."
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
            [alert show];

        }

我没有支持触摸ID功能的设备,因此在哪里可以对其进行测试以查看其功能是否正常。

任何帮助,将不胜感激。谢谢。

最佳答案

您只能在真实设备上测试TouchID。模拟器不支持此功能。

关于ios - 没有iPhone 5s设备时如何测试Touch ID功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29388962/

相关文章:

ios - iOS 8 中 LAContext 实例的生命周期如何表现?

ios - 如何将整个表格 View 捕获为图像,从中创建 .pdf 并通过电子邮件发送

ios - Swift:在动画播放时更改标签文本值

ios - 如何旋转 iOS 标签并使其贴在屏幕边缘?

ios - 你能依赖 NSString intValue 从不引发异常吗

使用 Firebase 的 Swift 和 Touch ID

iOS 8 Touch ID 错误 "User interaction is required."

ios - 防止在我的应用程序中使用未经授权人员的 TouchID 注册指纹

ios - 如何让标签中的文本显示出来?