Touch ID IOS 10需要10 - 15秒才能响应

时间:2017-08-01 12:25:25

标签: ios swift xcode touch

我正在尝试在我的应用中实现触控ID。 我得到了触摸ID,但是在我被推到下一个Viewcontroller之前需要10到15秒。 我搜索了这个主题,似乎解决方案是在主线程中运行它。 然后我改变了我的代码来运行它作为主线程(我认为),但问题仍然存在。 谁能看到什么错了?

func logMeIn(){

    performSegue(withIdentifier: "notesVC", sender: self)
}


@IBAction func loginButton(_ sender: Any) {

    let context:LAContext = LAContext()

    if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil){
        context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Log in", reply: { (wasSuccessful, error) in
            if wasSuccessful{
                OperationQueue.main.addOperation({() -> Void in })
                self.logMeIn()
            }
            else {
                self.view.backgroundColor = UIColor.red
            }
        })
    }
}
}

1 个答案:

答案 0 :(得分:1)

这不是你在主线程上运行的方式。您需要移动需要在addOperation闭包内的主线程上运行的所有代码,如下所示:

if wasSuccessful{
    OperationQueue.main.addOperation({() -> Void in self.logMeIn()})
} 

或者你也可以

DispatchQueue.main.async{
    //write the code you want to run on the main thread here
}
相关问题