Search code examples
iosswiftwkwebview

How to specify timeout intervals for WKWebView requests?


I was wondering if there was any way to specify a timeout for every request made in a WKWebView.

For example, when I first load a url in my WKWebView, I do the following:


 if var URLRequest = createRequest(route: route) {
        URLRequest.timeoutInterval = 1.0
        webView.load(URLRequest)
 }

Note, the 1.0 is just an example Im using for a quick test.

This timeout works and is handled in my didFailProvisionalNavigation withError.

After handling it though and selecting another link in the webView, the timeoutInterval from my original request is ignored.

Is there anyway to set a timeoutInterval for all requests made for a WKWebView?


Solution

  • Is there anyway to set a timeoutInterval for all requests made for a WKWebView?

    No. If you were using URLSession the case would be otherwise, but as things stand you will just have to attach the timeout to the request as you are doing.