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

后端 未结 6 1995
故里飘歌
故里飘歌 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 00:53

    Choose scheme -> Diagnotics, remove main thread checker, then the warning will disappear. scheme editor

    0 讨论(0)
  • 2020-12-01 00:59

    Wrap the lines of code that modify the UI in DispatchQueue.main.async {} in order to make sure they execute on the main thread. Otherwise, you may be calling them from a background thread, where UI modifications are not allowed. All such lines of code must be executed from the main thread.

    0 讨论(0)
  • 2020-12-01 01:03

    I think the solution is already given, For my issue is Keyboard on the way.

    UIKeyboardTaskQueue may only be called from the main thread

    0 讨论(0)
  • 2020-12-01 01:13

    Refer this link https://developer.apple.com/documentation/code_diagnostics/main_thread_checker

    For me this worked when I called from block.

    0 讨论(0)
  • 2020-12-01 01:14

    First, make sure your invocations of google maps and ui changes are called from the main thread.

    You can enable the Thread Sanitizer to find offending lines.

    You can put offending lines on the main thread with the following:

    DispatchQueue.main.async {
        //Do UI Code here. 
        //Call Google maps methods.
    }
    

    Also, update your current version of google maps. Google maps had to make a couple of updates for the thread checker.

    For the question: "Why would this be occurring?" I think Apple added an assertion for an edge case which Google then had to update their pod for.

    0 讨论(0)
  • 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 {}

    0 讨论(0)
提交回复
热议问题