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

后端 未结 6 2015
故里飘歌
故里飘歌 2020-12-01 00:28

I am using google maps in Xcode 9 beta, iOS 11.

I am getting an error outputted to the log as follows:

Main Thread Checker: UI API called on a

6条回答
  •  天命终不由人
    2020-12-01 01:19

    It's hard to find the UI code which is not executed in main thread sometimes. You can use the trick below to locate it and fix it.

    1. Choose Edit Scheme -> Diagnostics, tick Main Thread Checker.

      Xcode 11.4.1

      Click the small arrow next to the Main Thread Checker to create a Main Thread Checker breakpoint.

      Previous Xcode

      Tick on Pause on issues.

    2. Run your iOS application to reproduce this issue. (Xcode should pause on the first issue.)

    3. Wrap the code that modify the UI in DispatchQueue.main.async {}

提交回复
热议问题