ios – 在后台线程com.google.Maps.LabelingBehavior上调用UI API

前端之家收集整理的这篇文章主要介绍了ios – 在后台线程com.google.Maps.LabelingBehavior上调用UI API前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
升级到XCode 9后,我在运行应用程序时突然收到以下警告:
Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 15473,TID: 773864,Thread name: com.google.Maps.LabelingBehavior,Queue name: com.apple.root.default-qos.overcommit,QoS: 21
Backtrace:
4   App                          0x000000010b8ee524 GMSIsApplicationInBackground + 53
5   App                          0x000000010b8dc77a -[GMSForegroundDispatchQueue initWithName:targetQueue:] + 269
6   App                          0x000000010b9bc5ee _ZN7gmscore6vector4text8GlyphSetC2ERKNS_4base10reffed_ptrINS0_16TextureAtlasPoolEEEPU28objcproto17OS_dispatch_queue8NSObjectPK8__CTFontff + 344
7   App                          0x000000010b9bba58 _ZN7gmscore6vector4text10GlyphCache11GetGlyphSetEPK8__CTFontf + 214
8   App                          0x000000010b9b950e _ZN7gmscore6vector4text6GLText14PrefetchGlyphsERKNS_4base10reffed_ptrINS1_10GlyphCacheEEERKNSt3__16vectorItNS9_9allocatorItEEEEPK8__CTFontf + 22
9   App                          0x000000010b9b9611 _ZN7gmscore6vector4text6GLText14PrefetchGlyphsERKNS_4base10reffed_ptrINS1_10GlyphCacheEEEPK8__CTLinebf + 207
10  App                          0x000000010b9112df _ZN7gmscore6vector12GLPointLabel22PrefetchGlyphsForGroupEPNS0_12GLLabelGroupE + 181
11  App                          0x000000010b911207 _ZN7gmscore6vector12GLPointLabel14PrefetchGlyphsEv + 33
12  App                          0x000000010b98022a _ZN7gmscore6vector16LabelingBehavior23CreatePendingOperationsERKNSt3__13setINS_4base10reffed_ptrINS0_7GLLabelEEENS2_4lessIS7_EENS2_9allocatorIS7_EEEESE_SE_NS0_13LabelDrawModeE + 1096
13  App                          0x000000010b97fb9d _ZN7gmscore6vector16LabelingBehavior14RunLabelingJobERKNS_4base10reffed_ptrINS1_11LabelingJobEEE + 357
14  App                          0x000000010b97fa2a ___ZN7gmscore6vector16LabelingBehavior14CommitInternalEPNS_8renderer14EntityRendererE_block_invoke + 22
15  Foundation                          0x0000000110bb0948 __NSThreadPerformPerform + 334
16  CoreFoundation                      0x00000001117af2b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17  CoreFoundation                      0x000000011184ed31 __CFRunLoopDoSource0 + 81
18  CoreFoundation                      0x0000000111793c19 __CFRunLoopDoSources0 + 185
19  CoreFoundation                      0x00000001117931ff __CFRunLoopRun + 1279
20  CoreFoundation                      0x0000000111792a89 CFRunLoopRunSpecific + 409
21  Foundation                          0x0000000110b6ae5e -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 274
22  App                                 0x000000010b9bace5 -[GMSx_GTMSimpleWorkerThread main] + 337
23  Foundation                          0x0000000110b788ac __NSThread__start__ + 1197
24  libsystem_pthread.dylib             0x000000011323393b _pthread_body + 180
25  libsystem_pthread.dylib             0x0000000113233887 _pthread_body + 0
26  libsystem_pthread.dylib             0x000000011323308d thread_start + 13
Error Domain=kCLErrorDomain Code=0 "(null)"

当我将地图分配给我的视图时,我可以将其缩小到问题.

override func viewDidLoad() {
    super.viewDidLoad()
    UIApplication.shared.isIdleTimerDisabled = true
    GPSManager.instance.startGPS()
    setupLayout()


    map = GMSMapView.map(withFrame: CGRect.zero,camera: getCamera(location: initialLocation,zoom: 10))
    map.mapType = .hybrid
    map.delegate = self
    map.settings.consumesGesturesInView = false

    self.view.addSubview(map) <-- This is where is goes wrong
    self.view.sendSubview(toBack: map)

    configureMenus()
}

这是我可以解决的问题还是在Google地图中?干杯

解决方法

问题出在Google库中.

如果您不想要这种警告,可以在Scheme选项中禁用主线程检查器.

Go Product>方案>管理方案搜索您用于测试的方案,然后按左侧栏中的编辑…按运行,然后转到诊断并取消选中主线程检查器复选框.

如果您不想要这些警告,这只是一个时间解决方案.我不推荐它,因为你可以在后台线程中调用UI时引入错误

如果您有测试,则应禁用“测试”选项中的复选框,如我在Xcode 9,iOS 11,XCUITest failure: Main Thread Checker Flurry Analytics中所述,如果您不希望测试崩溃

原文链接:/iOS/333407.html

猜你在找的iOS相关文章