gpt4 book ai didi

iOS 生物认证 : Try Password work only after the second biometric fail attempt

转载 作者:行者123 更新时间:2023-11-28 23:31:16 25 4
gpt4 key购买 nike

我第一次在 iOS 上尝试生物认证。

我的 touch id 身份验证代码运行良好。但如果 touch id 失败,我想使用设备 PIN 码进行身份验证。但这仅在第二次 touch id 尝试失败后才起作用。第一次失败时,会显示一 strip 有“尝试密码”按钮的警报。但是当触摸它时,它不会转到屏幕输入设备密码,而是再次显示输入触摸 ID 警报。

现在,如果触摸 ID 再次失败并且我触摸“输入密码”按钮。将出现输入设备 PIN 码的屏幕。

但是为什么第一次不起作用呢?来自苹果文档:

The fallback button is initially hidden. For Face ID, after the first unsuccessful authentication attempt, the user will be prompted to try Face ID again or cancel. The fallback button is displayed after the second unsuccessful Face ID attempt. For Touch ID, the fallback button is displayed after the first unsuccessful Touch ID attempt.

我发现它可以与 Google Pay 等应用程序配合使用。我在这里做错了什么。

这是我的代码。

public partial class AuthenticationViewController : UIViewController
{

private LAContext context;

public AuthenticationViewController(IntPtr handle) : base(handle)
{
}

public override void ViewDidLoad()
{
base.ViewDidLoad();

if (UserDefaultsManager.RememberMe)
TryAuthenticate();
else
AppDelegate.Instance.GotoLoginController();
}

private void TryAuthenticate()
{
context = new LAContext();
NSError error = null;

if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0) &&
context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out error)) {
// Biometry is available on the device
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics,
"Unlock SmartFHR", HandleLAContextReplyHandler);
} else {
// Biometry is not available on the device
if (error != null) {
HandleLAContextReplyHandler(false, error);
} else {
TryDevicePinAuthentication(error);
}
}
}

private void TryDevicePinAuthentication(NSError error)
{
if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, out error)) {
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthentication,
"Unlock SmartFHR", HandleLAContextReplyHandler);
}
}

private void HandleLAContextReplyHandler(bool success, NSError error)
{
DispatchQueue.MainQueue.DispatchAsync(() => {
if (success) {
ContinueAfterAuthSuccess();
return;
}
switch (error.Code) {
case (long)LAStatus.UserCancel:
AppDelegate.Instance.GotoLoginController(true);
break;
case (long)LAStatus.UserFallback:
case (long)LAStatus.BiometryNotEnrolled:
case (long)LAStatus.BiometryNotAvailable:
TryDevicePinAuthentication(error);
break;
}
});
}

private void ContinueAfterAuthSuccess()
{
if (Storyboard.InstantiateViewController("SplashController") is SplashController vc)
AppDelegate.Instance.Window.RootViewController = vc;
}

}

当第一次触摸 ID 尝试失败并且我触摸“尝试密码”按钮时,我看到它调用了 HandleLAContextReplyHandler,并带有错误代码 LAStatus.UserFallback。

最佳答案

LAPolicyDeviceOwnerAuthentication 的文档说:

If Touch ID or Face ID is available, enrolled, and not disabled, the user is asked for that first.

因此,当您使用 TryDevicePinAuthentication 显示身份验证窗口时,它仍然会首先显示生物识别窗口。

如果你想让用户输入密码来进行身份验证,我认为DeviceOwnerAuthentication就足够了。

private void TryAuthenticate()
{
context = new LAContext();

// if Biometry is available on the device, it will show it first
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, "Unlock SmartFHR", HandleLAContextReplyHandler);
}

这样,只需处理用户取消本次认证的情况即可。因为当用户点击后备按钮时,它会自动弹出一个密码输入窗口:

private void HandleLAContextReplyHandler(bool success, NSError error)
{
DispatchQueue.MainQueue.DispatchAsync(() => {
if (success)
{
ContinueAfterAuthSuccess();
return;
}
switch (error.Code)
{
case (long)LAStatus.UserCancel:
AppDelegate.Instance.GotoLoginController(true);
break;
default:
break;
}
});
}

关于iOS 生物认证 : Try Password work only after the second biometric fail attempt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56394111/

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