gpt4 book ai didi

authentication - TouchID 转发到系统密码认证

转载 作者:行者123 更新时间:2023-12-03 22:19:58 26 4
gpt4 key购买 nike

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

1.我希望用户可以点击“输入密码”来调用系统内置密码屏幕进行身份验证,如果成功则进入我自己的应用程序。
但我不知道如何在“case LAErrorUserFallback”中将其转发到密码验证 View ,如下面的屏幕所示
enter image description here

这是我的代码:

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);

}


}];

最佳答案

现在在 iOS 9 中它实际上非常简单——你只需要使用 LAPolicyDeviceOwnerAuthentication而不是 LAPolicyDeviceOwnerAuthenticationWithBiometrics
所以在你的代码中你只需替换这个:

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

有了这个:
[context evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:NSLocalizedString(@"Unlock APP With FingerPrint", nil) reply:
^(BOOL success, NSError *authenticationError) {

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

关于authentication - TouchID 转发到系统密码认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25397184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com