如何从 Touch ID 警报视图中删除输入密码和取消按钮

How to remove Enter Password and Cancel button from Touch ID alert view

我卡住了,不想在拇指印象警报中输入密码

[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"UNLOCK_ACCESS_TO_LOCKED_FEATURE", nil) reply:
         ^(BOOL success, NSError *authenticationError)
         {
             if (success)
             {

                 msg =[NSString stringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_SUCCESS", nil)];
             }
             else
             {
                 msg = [NSString stringWithFormat:NSLocalizedString(@"EVALUATE_POLICY_WITH_ERROR", nil), authenticationError.localizedDescription];
             }
         }];
     }

看看LAContext.h,我发现了这个:

/// Fallback button title.
/// @discussion Allows fallback button title customization. A default title "Enter Password" is used when
///             this property is left nil. If set to empty string, the button will be hidden.
@property (nonatomic, copy) NSString *localizedFallbackTitle;

你应该设置localizedFallbackTitle = @"" -- empty string;。让我们尝试一下,如果有效,请接受答案。

要隐藏按钮 "Enter password",您需要将 localizedFallbackTitle 设置为空字符串。

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

// Hide "Enter Password" button
context.localizedFallbackTitle = @"";

// show the authentication UI
//...

关于 "Cancel" 按钮,我认为无法删除它。

希望对您有所帮助。

您可以删除 "cancel" 按钮,但在这种情况下您的应用将被拒绝

[context setCancelButtonVisible:false];

localizedFallbackTitle 属性 LAContext class。如果你想要自定义文本而不是“输入密码”那么你可以在这里设置。

如果设置为空字符串,则按钮将被隐藏。

下面是我用过的代码:

 //MARK: - scanFingerPrint
    func scanFingerPrint() {
        let authContext:LAContext = LAContext()
        authContext.localizedFallbackTitle = ""
    . . .
    }

看来 Apple 已经添加了自定义取消按钮标题的方法 iOS 10,

localizedCancelTitle

The localized title for the fallback button in the dialog presented to the user during authentication.

Discussion

This string should be provided in the user’s current language and should be short and clear.

https://developer.apple.com/documentation/localauthentication/lacontext/1643658-localizedcanceltitle

您可以根据需要更改取消按钮的标题

[context setLocalizedCancelTitle:@"ABC"];

你应该为 localizedFallbackTitle 使用像 "" 这样的空字符串
示例:

let context:LAContext = LAContext()
context.localizedFallbackTitle = ""