0

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

eharo2
  • 2,553
  • 1
  • 29
  • 39
  • 2
    This is a known issue in iOS 12. See https://github.com/Instabug/Instabug-iOS/issues/298 – matt Jul 16 '19 at 20:59
  • @matt I checked the bug report in the link. Thx for pointing me into that direction...It indeed seems to be a bug... The fact that a TestFlight build runs fine in the iPhone X made me think that it was not a device related issue. I will keep an eye in it – eharo2 Jul 16 '19 at 21:48
  • Just enable Thread Sanitizer from Xcode build settings. Then it will stop at line where memory leak is happening. Check this for how to enable Thread Sanitizer https://stackoverflow.com/a/45913510/1753005 – Jayprakash Dubey Jan 27 '21 at 07:53

0 Answers0