Ios LAContext evaluatePolicy并不总是提示用户
在我的iOS 7 iPad应用程序LAContext:evaluatePolicy中,有时会在不提示用户触摸ID按钮的情况下返回成功。苹果的文档说“评估一项政策可能涉及提示用户……”Ios LAContext evaluatePolicy并不总是提示用户,ios,touch-id,Ios,Touch Id,在我的iOS 7 iPad应用程序LAContext:evaluatePolicy中,有时会在不提示用户触摸ID按钮的情况下返回成功。苹果的文档说“评估一项政策可能涉及提示用户……” 我的身份验证策略设置为LAPolicyDeviceOwnerAuthenticationWithBiometrics,这是我看到的唯一选择。为什么每次我调用evaluatePolicy时都不会提示用户触摸ID按钮?有没有办法要求这种行为?我也遇到过类似的问题。 您可能正在声明一个全局变量,例如 let authen
我的身份验证策略设置为LAPolicyDeviceOwnerAuthenticationWithBiometrics,这是我看到的唯一选择。为什么每次我调用evaluatePolicy时都不会提示用户触摸ID按钮?有没有办法要求这种行为?我也遇到过类似的问题。 您可能正在声明一个全局变量,例如
let authenticationContext = LAContext()
然后在类方法和函数中使用authenticationContext
我已经开始在我使用的每个函数中声明常量
func someAuthFunc() {
let authenticationContext = LAContext()
...
我的问题解决了。
每次我要求评估或上下文时都会被问到
我希望这有帮助
干杯在iOS13更新后,我遇到了同样的问题。这不是一个很好的解决办法,但两次致电evaluatePolicy解决了我的问题
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { _, _ in
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { isSuccess, _ in
DispatchQueue.main.async {
if isSuccess {
success()
} else {
fail(authError?.localizedDescription ?? "User did not authenticate successfully")
}
}
}
}
这似乎是iOS 13、13.1上的一个bug,计划在13.2中修复。我建议您在iOS 13.2测试版上试用您的代码,看看是否更好
来源:针对有相同问题的人 它只发生在iOS 13及更高版本上。解决方案尝试调用
evaluate
函数两次,如下所示:
let systemVersion = UIDevice.current.systemVersion
// Trick here: Try to do a pre-evaluate
if systemVersion.compare("13.0", options: .numeric) != .orderedAscending {
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Authenticate to open the app", reply: { (_, _) in
//Ignore callback here
})
}
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Authenticate to open the app", reply: { (success, error) in
// Handle callback here
})
到目前为止,已在所有iOS 13.x.x版本中测试并运行良好。您介意将我的答案标记为正确答案吗?抱歉,您的答案没有解决我的问题。看起来它在13.1.3中已修复。可以确认这在13.1.3中仍然是一个问题。我喜欢您的解决方案,并且可以确认它正在运行。iOS 13.2已经修复了这个问题-你能调整你的代码只包括13.0和13.1吗?这是正确的吗?->如果systemVersion.compare(“13.0”,选项:。数值)!=。OrderedAsceding和&systemVersion.compare(“13.1”,选项:。数值)!=。orderedDescending{…}对于条件,如果它适用于iOS 13.0.x和13.1.x,并且已从iOS 13.2.x修复,则代码应为:
if systemVersion.compare(“13.0”,选项:。数值)!=。orderedAscending&&systemVersion.compare(“13.2”,选项:。numeric)=。orderedAscending{//13.0文档建议不应该发生这种情况,但它确实发生了:Auth0的SDK存储了一个私有的LAContext,这使得该SDK的用户在13.6上仍然会遇到问题