I made a iOS app with Xcode and Swift with only a WebView. Sometimes the website, render by that WebView, crash. In this case I want to reload the WebView.
To do that I read that there is a new trigger in iOS 9 who is called when :
the web view’s web content process is terminated.
Source : iOS Developer Library
So I add this function to my ViewController
file :
func webViewWebContentProcessDidTerminate(webView: WKWebView){
print("Reload");
self.webView!.reload();
}
But when my website crash nothing append, so I wonder: in which case webViewWebContentProcessDidTerminate is called ?
kristfal found some interesting behaviors :
If the app is running in the foreground, crash recovery is working very well via webViewWebContentProcessDidTerminate. It simply reloads the wkwebview. No new instance of the webview is created, so no more memory issues (the current implementation is leaking).
When the app is returning from the background, it is prone to crashing the webview without calling webViewWebContentProcessDidTerminate. The app will attempt to recover with a reload of the webview via applicationDidBecomeActive, but if it fails (which seems to happen around 1/10 times), it will crash the entire app to prevent getting stuck in an infinite loading loop.
Source : https://github.com/Telerik-Verified-Plugins/WKWebView/issues/248#issuecomment-235241805
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With