2

My main UIViewController contains a WKWebView. When opening the app, the WKWebView loads an URL in the UIViewController's viewDidLoad method. A web page is displayed in the WKWebView. When the app goes in the background state for a short time and goes back in foreground, the WKWebView reloads the URL. Concerning the WkNavigationDelegate there is no logic inside the didStartProvisionalNavigation method.

Question is : What makes WKWebView reloading when it is back to foreground state ?

Jibeee
  • 822
  • 1
  • 11
  • 26
  • What's the content at the given url you load into WKWebView? Maybe some JavaScript that triggers the reload? – mbi Jan 19 '21 at 12:24
  • I load a PWA inside the WKWebView. I'm using messages to communicate between PWA and WKWebview but the PWA doesn't receive nor handle infos concerning the state of the native mobile app. More info on communication between Web pages and WKWebview : https://medium.com/john-lewis-software-engineering/ios-wkwebview-communication-using-javascript-and-swift-ee077e0127eb – Jibeee Jan 19 '21 at 13:29
  • so maybe you call `evaluateJavascript` on your WKWebView instance when the app comes back to foreground and that in turn makes the content reload? – mbi Jan 19 '21 at 17:32
  • It's nearly impossible to answer your question without more detail about your specific case. I'm pretty sure there is no automatic reload of WKWebView on application state change in general. – mbi Jan 19 '21 at 17:35
  • 4
    Did you ever figure this out? I have the same problem. It is fine if it has only been backgrounded for a few seconds, or minutes. But after some time in background (?) it will do a full reload when brought into foreground. – Son of a Beach Sep 30 '21 at 06:58
  • @SonofaBeach I didn't find a solution to prevent the WKWebview from reloading. I catch the event of initialization and do my code here. Let me know if you find something – Jibeee Oct 04 '21 at 10:03
  • It is possible to prevent to reload the entire PWA (only Apple can think it is ok to reload an app once you got a phone call) if you override the resume method. But at this point the wkwebview shows a blank screen. Not really a solution :P I would also be happy to find a working solution for my browser app... – Adriano Jan 06 '22 at 08:05

0 Answers0