TouchID转发到系统密码验证

eri*_*ric 14 authentication fallback fingerprint ios8

我想使用TouchID验证我自己的应用程序.

1.我希望用户可以点击"输入密码"来调用系统内置密码屏幕进行身份验证,如果成功则输入我自己的应用程序.
但我不知道如何将它转发到密码验证视图,如'case LAErrorUserFallback'中的以下屏幕 在此输入图像描述

这是我的代码:

LAContext *context = [[LAContext alloc] init];
__block  NSString *msg;
__block  BOOL bAuth;
// show the authentication UI with our reason string
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"Unlock APP With FingerPrint", nil) reply:
^(BOOL success, NSError *authenticationError) {

   if (success) {
      bAuth = YES;
      msg =[NSString stringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_SUCCESS", nil)];
      dispatch_async(dispatch_get_main_queue(), ^{
         [[MYAppDelegate theDelegate] initializeAppAfterKeyVaultUnlocked];
      });
      NSLog(@"%@",msg);
   } else {
      bAuth = NO;
      switch (authenticationError.code) {
         case LAErrorAuthenticationFailed:
            msg = [NSString stringWithFormat:NSLocalizedString(@"Authentication Failed", nil)];
            // ...
            break;

         case LAErrorUserCancel:
            msg = [NSString stringWithFormat:NSLocalizedString(@"User pressed Cancel button", nil)];
            dispatch_async(dispatch_get_main_queue(), ^{
               [[MYAppDelegate theDelegate] exitAndLock];
            });

            break;

         case LAErrorUserFallback:
            msg = [NSString stringWithFormat:NSLocalizedString(@"User pressed \"Enter Password\"", nil)];
            //Here I want to fallback to iOS build-in passcode authenticate view, and get the auth result.
            break;

         default:
            msg = [NSString stringWithFormat:NSLocalizedString(@"Touch ID is not configured", nil)];
            // ...
            break;
      }
      NSLog(@"%@",authenticationError.localizedDescription);

   }


}];
Run Code Online (Sandbox Code Playgroud)

Dan*_*e P 13

现在在iOS 9中它实际上很简单 - 你只需要使用LAPolicyDeviceOwnerAuthentication而不是LAPolicyDeviceOwnerAuthenticationWithBiometrics

所以在你的代码中你只需要替换它:

[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"Unlock APP With FingerPrint", nil) reply:
^(BOOL success, NSError *authenticationError) {
Run Code Online (Sandbox Code Playgroud)

有了这个:

[context evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:NSLocalizedString(@"Unlock APP With FingerPrint", nil) reply:
^(BOOL success, NSError *authenticationError) {
Run Code Online (Sandbox Code Playgroud)

因此,当用户无法使用指纹进行身份验证时,会出现"输入密码"选项,该选项将调用系统密码输入屏幕.


小智 1

根据我的理解,如果您想使用evaluatePolicy,您将必须自己构建密码屏幕。

如果您使用钥匙串,则当指法失败时,SecItemCopyMatching 函数会自动回退到密码。以下是有关如何进行操作的参考(请参阅第 3 节):https ://www.secsign.com/fingerprint-validation-as-an-alternative-to-passcodes/