主线程检查器:在后台线程上调用UI API: - [UIApplication delegate]

时间:2017-06-13 05:26:18

标签: ios multithreading ios11 xcode9

Xcode 9似乎报告了许多对UIApplication属性的主线程调用。即使UI没有被更新,由于日志的扩展,它会产生一个默认环境,因此特别麻烦。

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

2 个答案:

答案 0 :(得分:5)

如果这些报告消息让您感到困惑取消选中

  1. 编辑方案... enter image description here
  2. 在“运行”>中取消选中“主线程检查器”诊断enter image description here

答案 1 :(得分:0)

还要检查ARKit template Xcode project Main Thread Checker log console

如果从另一个线程调用UIApplication或UIApplicationDelegate方法,则可以像CGN答案中一样禁用检查线程,但是它将完全禁用此检查器。您也可以将必要的子类化,并在主线程上调用超类的方法。这样,您仍然可以在代码的其他地方使用Main Thread Sanitizer