地图页面load后,调试出现如下异常:
Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 3317, TID: 82294, Thread name: Runtime Network Callback Thread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4 FQArcGISProj 0x000000010cfe5340 -[AGSRequestOperation kickoffConnection] + 1072
5 Foundation 0x00007fff208515d7 __NSThreadPerformPerform + 179
6 CoreFoundation 0x00007fff203724a7 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
7 CoreFoundation 0x00007fff2037239f __CFRunLoopDoSource0 + 180
8 CoreFoundation 0x00007fff2037186c __CFRunLoopDoSources0 + 242
9 CoreFoundation 0x00007fff2036bf68 __CFRunLoopRun + 871
10 CoreFoundation 0x00007fff2036b704 CFRunLoopRunSpecific + 562
11 Foundation 0x00007fff20828049 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 213
12 FQArcGISProj 0x000000010d0cf318 -[AGSThreadTargetImpl mainRoutine] + 264
13 Foundation 0x00007fff208511a1 __NSThread__start__ + 1009
14 libsystem_pthread.dylib 0x00007fff701cb4e1 _pthread_start + 125
15 libsystem_pthread.dylib 0x00007fff701c6f6b thread_start + 15
2023-01-11 16:20:29.480230+0800 FQArcGISProj[3317:82294] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 3317, TID: 82294, Thread name: Runtime Network Callback Thread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4 FQArcGISProj 0x000000010cfe5340 -[AGSRequestOperation kickoffConnection] + 1072
5 Foundation 0x00007fff208515d7 __NSThreadPerformPerform + 179
6 CoreFoundation 0x00007fff203724a7 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
7 CoreFoundation 0x00007fff2037239f __CFRunLoopDoSource0 + 180
8 CoreFoundation 0x00007fff2037186c __CFRunLoopDoSources0 + 242
9 CoreFoundation 0x00007fff2036bf68 __CFRunLoopRun + 871
10 CoreFoundation 0x00007fff2036b704 CFRunLoopRunSpecific + 562
11 Foundation 0x00007fff20828049 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 213
12 FQArcGISProj 0x000000010d0cf318 -[AGSThreadTargetImpl mainRoutine] + 264
13 Foundation 0x00007fff208511a1 __NSThread__start__ + 1009
14 libsystem_pthread.dylib 0x00007fff701cb4e1 _pthread_start + 125
15 libsystem_pthread.dylib 0x00007fff701c6f6b thread_start + 15
(lldb)
在左侧窗口可以定位到错误地址,如下所示:
![](https://i-blog.csdnimg.cn/blog_migrate/a871ada18b00af47b40c1ac7372415f2.png)
这是调用的第三方库UI不能在后台线程中执行,之前的版本都没问题,可能是IOS13以后新增加的检测。
参考:Main Thread Checker: UI API called on a background thread_skylin19840101的博客-CSDN博客
某些第三方带源码的库手动修改没问题。
但是,ArcGIS我用的是10.25版本,如果更新到最新版本100以上,改动特别大,因此,选择关闭主线程检测功能。
关闭方式:
Edit Scheme -> Diagnostics -> RuntimelyAPI Checking -> Main Thread Checker。去掉Main Thread Checker前面的对勾。
如下图所示:
![](https://i-blog.csdnimg.cn/blog_migrate/4b949175b02529e03d5c74b0369b2350.png)
只有在调试时才有这个选项,在Archive版本中没有。
参考:Xcode9 新特性之Main Thread Checker - 简书 (jianshu.com)
关闭了主线程检测后,调试时不提示错误了,但到那里仍然崩溃。
经过对代码的排查,发现是加载底图时出错了,底图时作为静态图层加载的,运行有后台线程。
ArcGIS sdk用的是10.25版本,升级100以上太麻烦了。
经过内测,发现真机都没问题,但是模拟器不行。
有没有大神可以指导一下,怎么跳过主线程检测呢?