"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 issue here. No problem with iOS 15, Xcode 13, but I get this warning with Xcode 14.1. I wonder if this is an issue with my app or a bug of Xcode 14.

same, but related to CoreLocation

# I have the same problem, I don't have a problem on ios 15 devices, but when opening webview on ios 16 devices, first a black screen comes for 1 second, then webview opens.

Any updates for this issues ? why we always have this warning with every wkwebview.load() call? is there any engineer from @Apple to explain the issues and how to avoid it ? what going wrong with wkwebview load method ?

An Apple engineer explained the issue in a separate thread here: https://developer.apple.com/forums/thread/714467?answerId=734799022#734799022

Short summary is that if the warning stack trace shows SecTrustEvaluateIfNecessary and SecTrustCopyCertificateChain followed by WebCore and WebKit code, then it's a known Apple issue. Using WKWebView causes Xcode to show this warning, and there's nothing devs can do to fix it. But it's just a noisy warning, not causing any real problem. Apple plans to fix the warning at some point but no ETA.

If you don't see the stack trace, you can expand the warning to view it by clicking the arrows ">" next to the purple warning icon in the left pane.

More details on the specific issue and on this Xcode diagnostic feature in general are in the thread linked above.

">

Same issue here, Xcode 14.1, When loading a request/URL in WKWebView

Hope it'll soon be fixed

I'm having the same issue when opening a WebView on our application.

Same issue, even without using webviews.

Same issue

Same issue with Xcode 14.2, any update?

Sama here, Xcode 14.2.

I am facing the same issue while loading a web Page. Before that, I met the same problem when I was using a library to embed youtube videos and that library also used web view to load youtube videos. it has no problem if we load a web page only a single time but the simulator hangs if we load the web page multiple times. I am afraid it can cause my app to crash.

This also seems to happen when making a SwiftUI application scriptable (integrating AppleScript responders like NSScriptCommand)

This does not happen directly when starting the app, but only after issuing it an AppleScript command. So I'm not entirely sure if this warning is right. Responding to AppleScript is blocking the main thread, but I don't see if there's another way as it seems to be all Apple internals.

I have 2 apps practically identicals (ver. Pro & lite) and I've the issue only in one.... The difference is that one have the googleAds and not the other. Is possible that this "error" be for this library.

What is the status of this bug? I am also having this issue and it has been 6 months of being asked, did you guys come up with any solution?

As I can see, it happens only in Simulator by using Web View. Tested on my Iphone IOS 15.7 without warnings.

Same here - This method should not be called on the main thread as it may lead to UI unresponsiveness. Xcode 14.2, target iOS 16.0. Cause: Google Ad Mob.

POSSIBLE LEAD ON WHAT'S CAUSING THE ISSUE/POSSIBLE SOLUTION TO LOOK INTO

this has happened me just now too. There was no such error until the last ten minutes and I've been running the app all day with no queries that would cause this.

The errors give no indication of what's wrong, but when I removed the last thing I added before the issues arose it resolved. I had created a String extension as per below and then tried to use it. When I removed the extension the issues disappeared again.

Probably not the exact same thing for everyone, but if you have a similar extension changing an Apple type then it looks like certain methods that take time to go do something shouldn't be used because it would delay the main thread - in my case i was trying to check if a string could be opened as a url. I'm guessing here and don't fully understand but least the issues seem to disappear. Wish there was more info in the warning itself to help us identify why!

//MARK: - Extension to check if string is a valid url

extension String {
    var isValidURL: Bool {

        if let url = NSURL(string: self) {
            return UIApplication.shared.canOpenURL(url as URL)
        }
        else if self.contains("https") == false &&  self.contains("www.") == true { //in case user didn't put https, check if added that
            let newstring = "https://\(self)"
            if let url = NSURL(string: newstring) {
                return UIApplication.shared.canOpenURL(url as URL)
            }
            else {
                return false
            }
        }
        else {
            return false
        }
    }
}

Having the same issue with an app that was working fine a few months ago, it went dormant, and now trying to do some more work on it. The app will do all sorts of async things, but I'm getting this right on the main thread as shown by the image below. The code the warning shows up on is below. It points to the line with "@main". And the stack trace is also just there (shows boilerplate code).

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Now, because a previous poster mentioned AdMob, I commented that out and the warning went away. I fixed it by just moving the AdMob init code into an async function, and that took care of the warning.

BUT JESUS! How about generating a warning that makes sense? Point to the line with the admob code!

You all can verify for yourselves, but Xcode 14.3 fixed this issue for me!

I'm seeing the same thing for a few recent Xcode releases. Happens when calling MTRegisterProfessionalVideoWorkflowFormatReaders(); inside AppDelegate init.

Filed as FB12137794

I get the same warning in XCode14.3. The warning is pointing at an Apple framework, AppleScriptObjC.framework.

@NSApplicationMain 
class AppDelegate: NSObject, NSApplicationDelegate 
{ 
   override init() 
   { 
      Bundle.main.loadAppleScriptObjectiveCScripts() // warning here
      ... 
   } 
   ... 
}

Seems like complain/issues only, no responses at all. Is this even usefull?

"UI unresponsiveness" warning on @main
 
 
Q