gpt4 book ai didi

ios - LocalAuthentication 框架 - 如何让 "Enter Password"在第一次调用时显示

转载 作者:搜寻专家 更新时间:2023-10-30 22:13:54 26 4
gpt4 key购买 nike

我正在使用适用于 iOS 的 LocalAuthentication 框架,并按照网络上的一般教程为我的应用程序实现 TouchID 身份验证。

当应用程序调用 context.evaluatePolicy(policy, error:&error) 时,我想向用户显示“输入密码”选项,而不是让用户选择“取消”以关闭对话框并输入密码。

这是 AppStore 应用程序中的默认行为,但我无法让我的应用程序以相同的方式执行。请参阅下面的 AppStore 屏幕截图:

AppStore TouchID Authentication

我使用的代码与那里的各种教程一致。请参阅下面的代码。

我的应用启动时出现以下屏幕:

My App TouchID authentication

我在 SO 和其他网站上进行了高低搜索,但无法使用“显示密码”启动我的应用程序。当我使用未注册的手指进行身份验证时,LA 对话框更改为“再试一次”并具有“显示密码”按钮。

        let context = LAContext()
var error : NSError?

// Test if TouchID policy is available on the device and a fingerprint has been enrolled.
var policy : LAPolicy!
if #available(iOS 9.0, *) {
policy = (context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error:&error) ? LAPolicy.DeviceOwnerAuthenticationWithBiometrics : LAPolicy.DeviceOwnerAuthentication)
} else {
// Fallback on earlier versions
policy = LAPolicy.DeviceOwnerAuthenticationWithBiometrics
}
if context.canEvaluatePolicy(policy, error:&error) {
// evaluate
context.evaluatePolicy(policy, localizedReason: reason, reply: {
(success: Bool, authenticationError: NSError?) -> Void in

// check whether evaluation of fingerprint was successful
if success {
okHandler()
} else {
// fingerprint validation failed
// get the reason for validation failure
var failureReason = "unable to authenticate user"
if let code = error?.code {
switch code {
case LAError.AuthenticationFailed.rawValue:
failureReason = "authentication failed"
case LAError.UserCancel.rawValue:
failureReason = "user canceled authentication"
case LAError.SystemCancel.rawValue:
failureReason = "system canceled authentication"
case LAError.PasscodeNotSet.rawValue:
failureReason = "passcode not set"
case LAError.UserFallback.rawValue:
failureReason = "user chose password"
default:
failureReason = "unable to authenticate user"
}
}
print("validation reason: \(failureReason).");
cancelHandler()
}
})
} else {
}

请帮忙!

最佳答案

你不能。用户必须至少“输入”一次错误的指纹才能让回退按钮出现。希望苹果在功能中添加一个属性。

关于ios - LocalAuthentication 框架 - 如何让 "Enter Password"在第一次调用时显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36462897/

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