我正在使用iOS的LocalAuthentication框架,并遵循了web上的一般教程来为我的应用程序实现TouchID身份验证。
当应用程序调用context.evaluatePolicy(policy,error:&error)时,我想向用户显示一个“输入密码”选项,而不是让用户选择“取消”关闭对话框并输入密码。
这是AppStore应用程序的默认行为,但我无法让我的应用程序以相同的方式执行。请看下面的AppStore截图:

我使用的代码与各种教程一致。请参阅下面的代码。
我的应用程序将启动,屏幕如下:

我已经到处搜索,在SO和其他网站上,但还没有能够启动我的应用程序与“显示密码”。当我使用未注册的手指验证LA时,对话框更改为"Try Try“,并有"Show Password”按钮。
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 {
}请帮帮我!
发布于 2016-04-18 09:36:29
你不能。用户必须至少“输入”一次错误的指纹,才能让回退按钮出现。希望苹果在这个功能中增加一个属性。
发布于 2017-10-16 18:29:04
不幸的是,您不能这样做,出于安全和隐私的原因,本地身份验证框架非常有限。
https://stackoverflow.com/questions/36462897
复制相似问题