代码之家  ›  专栏  ›  技术社区  ›  user2493047

如何在没有iPhone 5s设备的情况下测试Touch ID功能

  •  1
  • user2493047  · 技术社区  · 11 年前

    我想在应用程序中实现touch-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];
    
            }
    

    我没有支持touch id功能的设备,所以我可以在哪里测试它,看看它的功能是否正常。

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

    1 回复  |  直到 11 年前
        1
  •  3
  •   Fogh    11 年前

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