gpt4 book ai didi

ios - FaceID/TouchID 成功案例不断提示进一步验证

转载 作者:行者123 更新时间:2023-11-28 06:05:09 34 4
gpt4 key购买 nike

我已经在 View Controller 上实现了密码/TouchID/FaceID,当我遇到成功案例时,我希望提示停止触发,但它只是一遍又一遍地触发。

在我的 VC 中:

var context: LAContext!

func authenticateReturningUser() {
context = LAContext()
var error: NSError?

if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
let reason = "Verify that this is your device to continue."

context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { success, error in
DispatchQueue.main.sync {
guard success else {
guard let error = error else {
// show error
return
}

switch error {
case LAError.userCancel:
// do stuff
return
default: return
}
}

print("success")
}
}
}
}

如果用户成功授权,提示应该触发一次,而不是再次触发

编辑:

authenticateReturningUser 从 AppDelegate 的 applicationDidBecomeActive 函数调用:

self.coverVC?.completionHandler = { self.removeBackgroundVC() }
self.coverVC?.authenticateReturningUser()

最佳答案

据我所知,当显示 Touch ID 提示时,您的应用程序变为非事件状态。因此,当提示消失时,您的应用会再次激活,再次触发 App Delegate 的 applicationDidBecomeActive

您可能会考虑引入一个标志来存储应用程序是否因 Touch ID/Face ID 等或其他原因而变得不活跃,并在 applicationDidBecomeActive 中使用它来决定是否应触发身份验证或不是。

关于ios - FaceID/TouchID 成功案例不断提示进一步验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48450446/

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