Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 276
p0ny Avatar asked Nov 23 '25 12:11

p0ny


1 Answers

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.

like image 121
matt Avatar answered Nov 25 '25 09:11

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!