主线程检查器:在后台线程 iOS 11 Xcode 9 GM Seed 上调用的 UI API

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46278957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:14:55  来源:igfitidea点击:

Main Thread Checker: UI API called on a background thread iOS 11 Xcode 9 GM Seed

objective-cxcodemultithreadingios11xcode9

提问by Madhu

Can anyone please help me in debugging this issue, from the time i started working with Xcode 9 GM seed with iOS 11 GM seed, my code throwing me a warning in the console saying:

任何人都可以帮助我调试这个问题,从我开始使用带有 iOS 11 GM 种子的 Xcode 9 GM 种子开始,我的代码在控制台中向我发出警告说:

2017-09-18 16:22:52.872716+0530 **** *****[359:20158] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication 
  applicationState] .PID: 359, TID: 20158, 
  Thread name: Runtime Network Callback Thread, 
  Queue name: com.apple.root.default-qos.overcommit, QoS: 21
  Backtrace:

also, i'm using ESRI maps in my application, when ever i zoom in or zoom out in ESRI maps i'm getting this error:

另外,我在我的应用程序中使用 ESRI 地图,当我放大或缩小 ESRI 地图时,我收到此错误:

  2017-09-18 16:22:53.176524+0530 *** ***[359:20063] Task <5F9376DB-9335-
  4A45-B3F0-1D6FD69A19A3>.<29> finished with error - code: -999
  2017-09-18 16:22:53.178923+0530 *** ***[359:20142] Task <0DE282EA-3FBD-
  4036-8298-C75EFA65F15A>.<40> HTTP load failed (error code: -999 [1:89])
  2017-09-18 16:22:53.179821+0530 *** *[359:20063] Task <BE2D8BAE-FFB8-
  43CA-8723-111326DEF4FD>.<31> finished with error - code: -999
  2017-09-18 16:22:53.180089+0530 *** ***[359:20063] Task <E7C819D4-C11A-
  4915-B021-A73F31BE89CD>.<33> finished with error - code: -999
  2017-09-18 16:22:53.180365+0530 *** ***[359:20063] Task <3B871761-B006-
  4220-B857-6204B385AD34>.<34> finished with error - code: -999
  2017-09-18 16:22:53.180523+0530 *** ***[359:20142] Failed to get 
  TCPIOConnection in addInputHandler.

Application works fine with Xcode 8 iOS 10.3.3. Problem seems to be with Xcode 9. Can anyone please help me in debugging this issue. Thanks

应用程序适用于 Xcode 8 iOS 10.3.3。问题似乎出在 Xcode 9 上。任何人都可以帮我调试这个问题。谢谢

回答by Sparga

Xcode 9 adds a new runtime checks which is the Main Thread Checker.

Xcode 9 添加了一个新的运行时检查,即Main Thread Checker

According to Apple documentation:

根据苹果文档:

The Main Thread Checker is a standalone tool for Swift and C languages that detects invalid usage of AppKit, UIKit, and other APIs on a background thread. Updating UI on a thread other than the main thread is a common mistake that can result in missed UI updates, visual defects, data corruptions, and crashes.

主线程检查器是 Swift 和 C 语言的独立工具,用于检测后台线程上 AppKit、UIKit 和其他 API 的无效使用。在主线程以外的线程上更新 UI 是一个常见的错误,它可能导致错过 UI 更新、视觉缺陷、数据损坏和崩溃。

You already had this issue in your app with Xcode 8. It's just that the tool to detect it was not there yet.

您已经在使用 Xcode 8 的应用程序中遇到了这个问题。只是检测它的工具还不存在。

In your case, it seems that it's a call to UIApplication.shared.applicationStatethat is causing this runtime issue.

在您的情况下,似乎是调用UIApplication.shared.applicationState导致此运行时问题。

You can configure your app scheme to stop execution when it happens. It is a checkbox in the Diagnosticstab, under the Main Thread Checkersection.

您可以配置您的应用程序方案以在它发生时停止执行。它是主线程检查器部分下的诊断选项卡中的一个复选框。