【问题标题】:UI API called on a background thread com.google.Maps.LabelingBehavior在后台线程 com.google.Maps.LabelingBehavior 上调用的 UI API
【发布时间】:2017-09-25 13:19:47
【问题描述】:

升级到 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 地图中?干杯

【问题讨论】:

标签: ios swift google-maps


【解决方案1】:

问题出在 Google 库中。

如果您不希望出现这种警告,您可以在 Scheme 选项中禁用 Main Thread Checker。

转到Product &gt; Scheme &gt; Manage Schemes 搜索您用于测试的方案,然后在左侧边栏中按Edit...Run,然后转到Diagnostics 并取消选中Main Thread Checker 复选框。

如果您不希望收到这些警告,这只是一种临时解决方案。我不推荐它,因为如果在后台线程中调用 UI 可能会引入错误

如果你有测试,你应该禁用 Test 选项中的复选框,正如我在 Xcode 9, iOS 11, XCUITest failure: Main Thread Checker Flurry Analytics 中解释的那样,如果你不希望测试崩溃

【讨论】:

  • 所以基本上我可以在 Google 更新时关闭警告并重新打开它们?
  • 是的,但是如果你经常使用线程和 UIKit,最好打开警告以避免奇怪的行为。我建议你让Run 处于活动状态并在Test 中禁用,直到谷歌更新它。
  • 我可以将有此问题的应用推送到 App Store 吗?它似乎没有破坏应用程序中的任何内容。
  • 是的,你可以这样做。
猜你喜欢
  • 1970-01-01
  • 2018-01-07
  • 2017-11-29
  • 2017-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多