Touch ID IOS 10 需要 10 - 15 秒才能响应
Touch ID IOS 10 takes 10 - 15 sec to respond
我正在尝试在我的应用中实现触控 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
}
})
}
}
}
这不是你在主线程上 运行 的方式。您需要将所有需要 运行 的代码移动到 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
}
我正在尝试在我的应用中实现触控 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
}
})
}
}
}
这不是你在主线程上 运行 的方式。您需要将所有需要 运行 的代码移动到 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
}