与viewController的performSegue发生线程错误? iOS

问题描述 投票:0回答:1

在我授权用户的TouchID之后,我试图跳到第二个视图控制器。我能够验证TouchID是否正常工作,但是我跳到另一个viewController时遇到问题。

我创建了一个SecondViewController和一个带有标识符“ dispenseScreen”的Segue。但是,每当我尝试跳到第二个屏幕时,我的程序就会崩溃。

@IBAction func touchID(_ sender: Any)
    {

        let context:LAContext = LAContext()

        //Removes Enter Password during failed TouchID
        context.localizedFallbackTitle = ""

        if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
        {
                context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "We require your TouchID", reply: { (wasCorrect, error) in

                self.isBiometryReady()
                if wasCorrect {
                    self.performSegue(withIdentifier: "dispenseScreen", sender: self)
                    print("Correct")
                }
                else {
                    print("Incorrect")
                }
            })
        } else {
            //Enter phone password if too many login attempts
            //Add message alerting user that TouchID is not enabled
        }

    }

我的代码中没有语义错误,但是当我尝试转到第二个视图控制器时,我收到了线程错误。

ios swift xcode viewcontroller
1个回答
0
投票

您正在尝试从evaluatePolicy的回调中执行segue。对于涉及UI的任何内容,您需要确保您位于主线程上:(wasCorrect, error) in DispatchQueue.main.async { ... }

© www.soinside.com 2019 - 2024. All rights reserved.