"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.

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."

Same issue here. When is this fix expected?

Went through the whole thread but didn't see any solutions to this. Our app displays a VC which has a WKWebView in it. It's still working and displaying the same content without a problem but that warning is a bit annoying and I'm not sure if it will cause issues on other iOS devices or not

Same here Xcode Version 14.0 (14A309), app runs fine, will ignore warning. Would be nice to generally be allowed to let wkwebview live in background-thread.

Same here Xcode Version 14.0.1 (14A400), app runs fine, but receiving that warning in AppDelegate.

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {....}

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.

First of all, this problem occurs with apps that use the admob library.

Among the apps I sell, there is a paid app with a different target (same code) in the same project. When I build this paid app in my project, I don't see this warning.

My paid app uses "Other Swifts Flag" to not include the admob library in the code from the build generation, and the admob library is not included in the app.

I contacted Admob and got a reply.

Admob is also aware of this issue. Admob believes it's a bug by Apple, and Apple is also aware of this bug. Maybe it will be improved in the next Xcode or iOS update.

My guess is that when using WKWebView in Admob, you get such a warning message.

FB11618231

Seems like a Bug in WebKit for me. I don't use admob and WKWebview ist not on the first ViewController. The App can be used without the warning until a WKWebView is called for the first time. Then the warning appears.

So these lines of the thread seems the important one:

I have written a simple View to help anyone trying to isolate this issue that I discovered while trying to find the source of this warning. In my instance, I am using WKWebView to load specific sites that seems to trigger the warning when load(_ request: URLRequest) method is called.

import SwiftUI
import WebKit

struct WebView: UIViewRepresentable {
    typealias UIViewType = WKWebView

    let webView: WKWebView

    func makeUIView(context: Context) -> WKWebView {
        return self.webView
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
    }
}

struct TestView: View {
    let webView = WKWebView(frame: .zero)

    var body: some View {
        ZStack {
            WebView(webView: self.webView)
            Button("Test", action: {
                Task.detached(priority: .background) {
                    await self.webView.load(URLRequest(url: URL(string: "https://www.apple.com")!))
                }
            })
        }
    }
}

Even when attaching the load(_ request: URLRequest) method to a background thread seems to cause the warning.

I am not expert in SwiftUI or the new Concurrency methods, but is there a 'proper' why that this method is supposed to be called off the main thread?

I am getting This method should not be called on the main thread as it may lead to UI unresponsiveness in Xcode 14 when running on iOS 16. I have submitted the bug report and here is my FB number: FB11655869

Problem in appdelegate class thread

when UiactivityController shows,Xcode says This method should not be called on the main thread as it may lead to UI unresponsiveness. in appdelegate class.

DispatchQueue.global.async. DispatchQueue.global(qos: .background).async. don't help.

what is this?

Bueller? Bueller? No updates after 2 weeks? Issue still exists.

This warning is unnecessary and shouldn't show for apps that are otherwise working fine. Not everything has to be optimised perfectly to run in the background if it's responsive enough - please remove the warning in the next version of Xcode Apple.

Same problem came out of nowhere, the app still work great. After I updated macOS to Ventura 13.0 and Xcode I get this warning.

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

Weird that Xcode does not propose a solution. I suspect it is just an Xcode bug.

Same thing here, when I comment out WKWebView.load() the warning goes away. But when I try to set the loading to a background thread, it throws a thread error and gives this warning: "WKWebView.load(_:) must be used from main thread only"

So I can't have it on the main thread, but it can only be on the main thread...

FB11742846

I also have this security warnings 40+ on Xcode 14.1: 0x0000000000000000 in SecTrustEvaluateIfNecessary ().

I have encountered this same error when loading a view controller with a WKWebView. I filed FB11771307.

Do we have solution or know what risks we run into when we need to show WKWebView on launch?

Same issue!

Same issue!

"UI unresponsiveness" warning on @main
 
 
Q