ios - 使用 viewController 的 performSegue 线程错误?iOS
问题描述
在我授权用户的 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
}
}
我的代码中没有语义错误,但是当我尝试转到第二个视图控制器时收到线程错误。
解决方案
您正在尝试在evaluatePolicy
. 对于涉及 UI 的任何事情,您需要确保您在主线程上:(wasCorrect, error) in DispatchQueue.main.async { ... }
推荐阅读
- android - AdMob 真实广告不显示
- python - 安装 Pygal 的问题
- scala - 如何将枚举类型传递给函数
- javascript - Jeditable 未正确提交
- postgresql - 使用 shell 脚本(postgresql)中的替换函数将单词替换为“(双引号)
- angular - 如何使用角度将对象添加到包含 Array 的现有动态秋田商店
- node.js - 如何设置从 Node 服务器到 React 前端的音频流?
- networkx - 防止特定边缘组合的最短路径
- amazon-cloudformation - 在云形成模板的数据管道对象列表中添加 EMR 配置时数据管道验证错误
- javascript - 如果参数是数字,为什么函数返回 NaN?