iOS 13: @objc VC.navigationController(_:willShow:animated:) :线程违规:预期主线程

iOS 13: @objc VC.navigationController(_:willShow:animated:) : threading violation: expected the main thread

当隐藏特定 ViewController 的 NavigationBar 时,只有 iOS 13 个用户在 Fabric 的 Crashlytics 上崩溃。

我尝试通过使用 NavigationController 的委托方法隐藏特定 ViewController 的 NavigationBar

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
    let hide = (viewController is MyVC)
    navigationController.setNavigationBarHidden(hide, animated: animated)
}

但它也会在名为

的 crashlytics 上产生崩溃
Fatal Exception: NSInternalInconsistencyException

threading violation: expected the main thread

在主线程中隐藏它

Dispatch.main.async {
    navigationController.setNavigationBarHidden(hide, animated: animated)
}

您是否从后台线程调用 navigationController.setNavigationBarHidden

尝试:

DispatchQueue.main.async { [weak self] in
     self?.navigationController?.setNavigationBarHidden(hide, animated: animated)
}

我找到了上述问题的解决方案,

我使用 Xcode 10.2.1 上传了应用程序的构建,现在我没有遇到任何崩溃。