I'm trying to disconnect or stop loading URL request in 15 secs, when internet connection get disconnected. i tried with setTimeoutInterval in NSURLRequest, which is not working. can any know how to resolve the issue?
Here is an example for you:
NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:link]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0];
Here you have a 20 sec timeout interval.
From what I have experienced, this example from Oleg will not work. I guess you're facing the same problem as me and from what I have read online, maybe this solution will work for you too.
Using NSTimer, set the timer to start at the webViewDidStartLoad delegate method, and then make sure that you have counters at the webViewDidFinishLoad and webViewDidStarLoad methods to check if the webView has been loaded (this is an ugly hack, but unless you use javascript to check the number of elements in your page, there is really no way to know how many times these 2 methods will be called).
After doing so, do a check of the counters at the method that you are running after the timer has reached its time, and that should work.
The NSTimer code is here --> http://www.iphonedevsdk.com/forum/iphone-sdk-development/14403-nstimer-examples.html
Hope this helps, it did for me. Although I know there are flaws, it works for me as I am loading a splash screen which is supposed to be lightweight in the first place. I'm still looking for solutions though, will post edits here if I have other alternatives.
Feedback is greatly welcomed!
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