views:

173

answers:

1

I've got a wierd problem with NSURLConnection. I've set the connection time out of 20 seconds like this.

NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
NSURLConnection *con= [[NSURLConnection alloc] initWithRequest:request delegate:self];

I'm implementing the delegate methods for the NSURLConnection as well.

Now when I ran the app, the connection did not time out after 20 seconds but after 2-3 minutes it gave error for 'No internet connection'. Isn't it supposed to give a timeout error after 20 seconds?

+1  A: 

The discussion for timeoutInterval says that it starts (is set to 0) when a process of load activity occurs:

The timeout interval specifies the limit on the idle interval alloted to a request in the process of loading. The "idle interval" is defined as the period of time that has passed since the last instance of load activity occurred for a request that is in the process of loading. Hence, when an instance of load activity occurs (e.g. bytes are received from the network for a request), the idle interval for a request is reset to 0. If the idle interval ever becomes greater than or equal to the timeout interval, the request is considered to have timed out. This timeout interval is measured in seconds.

No internet connection is an error. So probably the timeout will actually occur in 20 seconds (set time) if it gets a connection but takes more time to load...

lukya
May be. But the discussions in [here](https://devforums.apple.com/thread/25282) also suggest that timeoutInterval is 240 seconds minimum for iphone if connection request has a body. So no matter what, it will atleast take 240 seconds if there's a body unless I cancel the connection after 20 seconds.