ios - TouchID 取消应该关闭 View Controller

标签 ios swift touch-id

对于我的应用程序,我需要使用 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/

相关文章:

ios - 如何使用 UIButton 为单元格设置动画?

objective-c - 为什么 Objective-C 中的头文件顶部同时有 import 和 class 语句?

swift - 苹果 watch http 请求

ios - SecAccessControl 没有成员 takeRetainedValue

ios - 如何制作 iOS Assets 包?

ios - 由于信号 : Segmentation fault: 11 Xcode 7. 2,命令失败

swift - 二维数组 swift 填充代码和描述为空

ios - 显示三个点的 UIButton 标签

ios - Swift ios touch id 登录流程

ios - 如何在 iOS 10 中使用 TouchID