我正在开发需要Touch ID身份验证的应用程序,所以我可以在模拟器中使用Touch ID(指纹扫描仪)吗?

另外,请分享一些使用LocalAuthentication框架的示例代码。

最佳答案

从Xcode 7开始,模拟器支持'touchID'。下面的答案包含更多信息。

从最新的beta(6)开始,无法在模拟器上模拟指纹扫描。老实说,我怀疑即使在以后的beta中也将包括在内。

您将需要在设备上进行测试。

要立即使用身份验证框架,您需要:
* XCode 6
*带iOS 8的iPhone 5s

您需要执行的步骤是:

找出设备是否支持指纹验证以及是否注册了指纹:

@import LocalAuthentication;

// Get the local authentication context:
LAContext *context = [[LAContext alloc] init];

// Test if fingerprint authentication is available on the device and a fingerprint has been enrolled.
if ([context canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil])
{
    NSLog(@"Fingerprint authentication available.");
}

仅验证指纹:
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"Authenticate for server login" reply:^(BOOL success, NSError *authenticationError){
    if (success) {
        NSLog(@"Fingerprint validated.");
    }
    else {
        NSLog(@"Fingerprint validation failed: %@.", authenticationError.localizedDescription);
    }
}];

根据用户的选择来验证指纹或设备的密码:
这超出了此处问题的范围,请在以下位置找到更多信息: https://www.secsign.com/fingerprint-validation-as-an-alternative-to-passcodes/

10-08 07:53
查看更多