Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling a NSURLRequest with timeout when using delegate

I'm using a NSMutableURLRequest to connect to a web site to get a JSON response. I'm doing so by generating the request, and then using NSURLConnection with a delegate of self to handle the async connection. I've implemented all the normal delegate methods:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
- (void)connectionDidFinishLoading:(NSURLConnection *)connection

All works perfectly with getting data back, dealing with any errors that occur, etc. However with the timeout on the NSURLRequest set to 10 seconds I don't seem to get called in those methods (I expected the didFailWithError to get called). It just sits there forever and I have no notification that it timed out.

Reading the iPhone API docs I don't see any mention of what should happen when the timeout occurs, just that you can set the timeout value. What should happen? I didn't see any other delegate methods in the API that would help. I don't have to manually check for timeouts, do I? Are timeouts only for synchronous requests?

like image 589
Parrots Avatar asked Aug 10 '09 00:08

Parrots


3 Answers

Your timeout is received in this method:

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
like image 149
Corey Floyd Avatar answered Oct 31 '22 15:10

Corey Floyd


u will br receiving such type of iofo:

in did fail with

error: Error Domain=NSURLErrorDomain Code=-1001 UserInfo=0xed4870 "timed out"

like image 35
Sandeep Kumar Avatar answered Oct 31 '22 17:10

Sandeep Kumar


The timeout behaviour is a bit quirky, see this thread on Apple’s developer forums.

like image 3
zoul Avatar answered Oct 31 '22 17:10

zoul