Main Thread Checker: UI API called on a background thread: -[UIApplication delegate]

99封情书 提交于 2019-12-01 15:15:15

问题


Xcode 9 seems to be reporting a lot of Main thread calls to UIApplication properties. Even though the UI is not being updated this is particularly cumbersome due to the extension of logs it produces a default environment.

4   TestApp                             0x0000000101c262e0 __39-[ViewController viewDidLoad]_block_invoke + 196
5   libdispatch.dylib                   0x0000000102279654 _dispatch_call_block_and_release + 24
6   libdispatch.dylib                   0x0000000102279614 _dispatch_client_callout + 16
7   libdispatch.dylib                   0x0000000102289008 _dispatch_queue_serial_drain + 716
8   libdispatch.dylib                   0x000000010227ce58 _dispatch_queue_invoke + 340
9   libdispatch.dylib                   0x000000010228a1c4 _dispatch_root_queue_drain_deferred_wlh + 412
10  libdispatch.dylib                   0x00000001022917fc _dispatch_workloop_worker_thread + 868
11  libsystem_pthread.dylib             0x00000001ac6771e8 _pthread_wqthread + 924
12  libsystem_pthread.dylib             0x00000001ac676e40 start_wqthread + 4

回答1:


If these reporting messages confuse you uncheck them:

  1. Edit Scheme...
  2. Uncheck "Main Thread Checker" in Run > Diagnostics



回答2:


Check also ARKit template Xcode project Main Thread Checker log console.

If UIApplication or UIApplicationDelegate method is called from another thread you can disable checking thread as in CGN answer, but it will disable this checker completely. You can also subclass what is necessary and call metod of superclass on main thread. This way you can still use Main Thread Sanitizer in other places in code



来源:https://stackoverflow.com/questions/44512977/main-thread-checker-ui-api-called-on-a-background-thread-uiapplication-deleg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!