"UI unresponsiveness" warning on @main

I'm seeing a runtime warning in Xcode 14 Beta 5 that says "This method should not be called on the main thread as it may lead to UI unresponsiveness."

This is happening on the @main entry point of my app. See below:

The warning shown gives me no insight into what's actually going wrong. I think it may be due to some Core Location code that runs when the app first opens, but is there a way for me to get some more insight into what's causing this?

Or is this possibly an Xcode 14/iOS 16 bug, and this is not an issue to worry about? I'm not getting any warnings on Xcode 13/iOS 15.

Answered by DTS Engineer in 730526022

The purple warning is calling attention to a runtime issue that may impact the performance of your app. In general, you should resolve these issues when they are in your code, by moving the code off the main thread. When you receive one of these runtime performance issues, you can expand the backtrace in the Issue Navigator, available through the View > Navigators > Issues menu, to see where the issue is located.

If you find the issue is pointing at an Apple framework, please use Feedback Assistant to open a bug report to let us know, and include the complete backtrace shown in the issue navigator. You can post the FB numbers to this thread for visibility. Further, if you can't identify where the issue is coming from, as the backtrace points to your main function, please also let us know, including the provided backtrace.

If you find the runtime issue is resulting from an Apple API call used in a sub-optimal way within a third-party library that your app uses, please open a bug report with the library vendor.

Same here after update to Xcode 14.0 today

Same issue is there any Fix for this?

In my case, I spotted the error on line 2, in viewDidLoad (but same issue if put elsewhere like viewDidAppear):

1.         guard let url = URL(string: "https://google.com") else {return}
2.         myWebView.load(URLRequest(url: url))

Problem: load MUST run on main thread (dispatching to another queue causes run time crash) WKWebView.load(_:) must be used from main thread only

Dispatching to main.async, logically does not change anything. That occurs in Xcode 14 / iOS 16 simulator. Also occurs with Xcode 13.4.1 / iOS 16. No such error message in Xcode 13.4.1 / iOS 15.5 So that's a new warning in iOS 16. I read there is a solution by prelaoding, but did not test yet. https://coderwall.com/p/trjkcg/preloading-uiwebview-or-wkwebview-in-swift

It is just a warning, if it works OK on real app, I think we should just ignore it.

Same for me with WKWebView

Same issue. What is going on with Xcode?

Same issue. How to fix it ?

I am seeing the problem with the simulator..but not when running on a real iPad..

Simulator Version 14.0 (986.3) SimulatorKit 624 CoreSimulator 857.7

I have a SwiftUI App that displays an animated gif from a weather api, using UIViewRepresentable and WKWebView. I also get this warning. I'm using the Xcode RC. I've checked the preloading solution, but not sure how I can apply this to an App with SwiftUI lifecycle.

Same purple security warning in Xcode 14 (latest release) here. "This method should not be called on the main thread as it may lead to UI unresponsiveness."

In my case I've traced it to a WKWebView -> loadRequest:, i.e. called from my main ViewController's -> viewDidLoad:

i.e. I load a web view at app startup, as after launch/splash screen it's the first view user will see. I'm careful about accounting for network issues and will timeout (or not even try loading), display an alternative screen, etc. if there are network issues.

I'm going to assume someone on the Xcode team chose to add this warning in the event a developer doesn't account for slow loading or not loading at all an initial wkwebview when the app first launches?

Any other theories? Is it safe to ignore the warning?

same issue here

In my case, the app works fine (even with this warnings), but image are loaded but a bit slow than before, just the other places where this warning is shown :(.

purple warning:

This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the -locationManagerDidChangeAuthorization: callback and checking authorizationStatus first.   

code:

    if(CLLocationManager.locationServicesEnabled())     {       locationManager.requestLocation()     }

     

however!

did not happen until xcode 14 upgrade,

i now have auto update off, Murphy's law got me :0)      

I want to resolve purple warning. I use WkWebView. Anyone have a solution?

purple warning: This method should not be called on the main thread as it may lead to UI unresponsiveness.

same issue

Same here! Happened after upgrading iOS and Xcode.

"This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the -locationManagerDidChangeAuthorization: callback and checking authorizationStatus first."

"UI unresponsiveness" warning on @main
 
 
Q