"Main Thread Checker: UI API called on a background thread" error in iPhone Xs, works fine in Simulator

5.5k Views Asked by At

I am working with Xcode 10.2.1 (last stable release), on MacOS 10.15 Catalina Beta (19A50501i), using Swift 5. The iPhone Xs has iOS 12.3.1

I checked multiple questions related to "UI API called on a background thread", but none seem to address my issue.

I have a complex app that I have been working for over 8 months and multiple AppStore updates. I recently migrated my device from iPhone 8 to iPhone Xs, and now I am getting this error message in the initial fetch. I am not able to pinpoint the code that is causing the issue.

  • Compile from Xcode to iPhone 8 ---- Everything is OK
  • Compile in the iPhone Xs simulator ---- OK
  • Install in my device (iPhone Xs) from TestFlight ---- OK. (The problem never surfaced before because all my testers with iPhone Xs get the app via TestFlight).

Only when compiling from Xcode to the iPhone Xs or iPhone XR, it reports the "Main Thread Checker: UI API called on a background thread" message and then after a 5 sec delay (blocking the UI), everything proceeds as usual.

The only UI code in the initial fetch is related to showing a HUD. I have disabled it with the same result

I tried the answer from this post: Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState] to try to get the code line, pausing on issues:

enter image description here

But, it pauses in the ret line of an assembler call

enter image description here

The stack trace info is not useful. The only code that I can look into is the Realm Listener (that I also disabled)

enter image description here

Other than a class method in a UIScreen extension to check the absolute height of the screen and a couple of constraints related to the iPhone X (or newer) safe area, there are no other iPhone Xs specific code.

Also, I am not using any CoreMotion code.

FINALLY, I use "DispatchQueue.main.async { }", in multiple areas of the project given the limitations of Realm when using other queues and also to manage the UI.

Any help will be appreciated

0

There are 0 best solutions below