In my controller I have a call to WKWebViewInstance.loadRequest(url). If there is no internet available, I want to load an error message in the WKWebView.
I have found that
func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError)
gets called when a WKWEbView navigation fails with no internet connection. When I make the webView.loadHtmlString() call inside the above delegate method, nothing happens.
How do I detect the absence of network connection while WKWEbView navigation request is made and load a fixed error message into web view instead?
My delegate method code is
func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
webView.stopLoading()
webView.loadHTMLString(Constants.OfflineHtmlString!,baseURL: nil)
}