对于我的应用程序,我需要使用 TouchID 保存它的一页。因此,用户有点被迫使用 TouchID,或者如果设备不支持它,则使用密码。如果用户取消TouchID认证,我想让View消失,回到 Root View 。我已经有那个工作了,但不知何故它不再工作了,我真的不知道为什么?!我只是复制到取消选项,其余的我想都无所谓。
func authenticateUser() {
let context = LAContext()
var error: NSError?
let reasonString = "Authentication is needed to access your App"
if context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &error){
context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString, reply: { (success, policyError) -> Void in
if success {
print("authentification successful")
}
}else{
switch policyError!.code{
case LAError.SystemCancel.rawValue:
print("Authentification was canceled by the system")
case LAError.UserCancel.rawValue:
print("Authentication was canceled by user")
self.navigationController?.dismissViewControllerAnimated(true, completion: nil)
//Yes I also tried popToRootViewController, still doesn't work
}
最佳答案
evaluatePolicy 调用的文档说:
“策略评估完成时执行的回复 block 。此 block 在未指定的线程上下文中的框架内部的私有(private)队列上进行评估。”
所以问题是您正试图从错误的线程调用导航。您需要在 UI 线程上进行该调用。例如:
dispatch_async(dispatch_get_main_queue()) {
// Navigation goes here
}
关于ios - TouchID 取消应该关闭 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35572470/