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

I have the same problem with the main function

Post not yet marked as solved Up vote post of iOS_wzb Down vote post of iOS_wzb
23k views

Replies

Any idea what's causing this? I'm seeing this when I show a WKWebView

help any idea??

I am having the same issue on Xcode 14 RC after opening an existing project in XC14 and running it. There is no other information, nothing to tell me which method is causing the problem.

In my case, I spotted the error on line 2, in a viewDidLoad:

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

Same purple warning in Xcode 14 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 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?

Seems to be fixed in Xcode 14.0.1?

  • Seems to be an issue with iOS 16.1(Shipped with XCode 14.1) and not an issue with iOS 16(Shipped with XCode 14.0.1).

Add a Comment

It's not fixed in Xcode 14.1 Beta. Didn't tried 14.0.1 yet.

You are facing this issue is because you might be using WKWebView's load request in main thread. So anywhere you are using loadRequest method, You should use

instead of this webView.load(request)

Use DispatchQueue.main.async {

      self.webView.load(request)

  **  }**

And it will resolve your Error. (You must be facing this issue in latest iOS Version 16.0 or above)

  • This method was tried, but nothing worked. It's still showing the same problem

  • This won't help because wrapping code in DispatchQueue.main.async { } will still run that code on the main thread. (Just delayed.)

Add a Comment

@TusharSharma Did you test it ?

I tried (as told in my previous answer) but that did not change anything.

  • is not working...

Add a Comment

me too

Post not yet marked as solved Up vote reply of Aox Down vote reply of Aox

me too

Is there any solution besides DispatchQueue.main.async (which doesn't eliminate this message)? On iOS 16.1 WKWebView also failed to load a page with following message: "[Process] 0x1180018f0 - [PID=734] WebProcessProxy::requestTermination: reason=8" - don't sure is it related to loading from main thread or it's a different issue.

I've just tried the DispatchQueue.main.async "workaround" using the production release of Xcode 14.1, and the problem persists. Furthermore, if using a WKWebView in an app where multiple windows can be shown, (i.e. iPad or Mac), then closing a window holding the WKWebView will crash the app if that window has called load(URLRequest). My test harness is such a lightwight SwiftUI app, short of some magic .INFO setting that I'm missing, I can't see how my code is contributing to the fault.

My (unfounded) suspicion is that some magic code deep within WKWebView is making an async call for something like the default WKNavigationDelegate and that gives rise to the issue: but I could never prove that.

  • I have the same issue

Add a Comment

Same probleme here

same here