@joxi has been warned!
when I update my XCode to 14, I receive two warning messages.
This message should not be called on the main thread
as it may lead to UI unresponsiveness.
Is this a bug in Xcode 14? or do I have bug in my code?
Let's ask some questions and investigate.
First, WHY? Why would some of this code cause the UI to be unresponsive?
Hypothesis: Sometimes visiting a web page in Safari takes a while to load. Maybe calling a web page via WKWebView
may hang if the URL takes a while to resolve?
Test: Let's look at the documentation for clues.
See -> WKWebView documentation for load() method
The documentation says the load()
method returns an optional WKNavigation
object, which you're ignoring in your code.
What does the WKNavigation
provide?
See -> WKNavigation Documentation
When you ask a web view to load content or navigate to a page,
the web view returns a WKNavigation object that identifies your request.
As the load operation progresses, the web view reports progress of that operation
to various methods of its navigation delegate, passing them the matching WKNavigation object.
This might be the clue!
If the WKNavigation
object monitors the load operation progress, you might receive a code indicating unresponsive URL. In this case, your application might also suffer from UI updates.
As a work-around, you might want to first put up a "loading" graphic where your web view will be. Then monitor the progress of the loading web page via the WKNavigation
object. When the web page is finally loaded, you remove the graphic, and display the web page.
I've not actually tested this with code, but this seems cromulent.
Keep Coding!
Please return here with sample code and let us know how you solved this.