NSMutableURLRequest does not obey my timeoutInterval

I get a small image, so I need the timeout interval to be short. If the image is not sent after a few seconds, it will probably never be sent. For some unknown reason, my NSURLConnection never breaks, no matter how shorter I set the timeoutInterval .

 // Create the URL request NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.tumblr.com/api/write"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:0.00000001]; /* Populate the request, this part works fine */ [NSURLConnection connectionWithRequest:request delegate:self]; 

I have a breakpoint at - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error , but it never starts. My images continue to be published just fine, they appear on Tumblr, despite the tiny timeoutInterval .

+30
nsurlconnection nsurlrequest nsmutableurlrequest
Apr 29 '10 at 11:46 april
source share
3 answers

There, a thread on the Apple dev forums discusses this issue . Apparently, on the iPhone OS, the installer sets a timeoutInterval of at least 240 seconds (4 minutes). This only happens when postBody is not empty (usually when using a POST request). This seems crazy, but he seems to have to make sure that the requests leave the system, even if it might take many seconds for the WWAN (3G) interface to wake up. 240 seconds seems pretty cool, so they suggest setting a timer and canceling an asynchronous connection when the timer fires. I know this seems silly, but only I managed to get a timeout for POST requests ... :-(

+49
May 05 '10 at 20:59
source share

As François mentioned, 240 seconds seemed to work as he described before iOS 6 (including 5.1). Now this timeout seems to take a default value of 60 seconds, as expected (unless you explicitly set it yourself), so if you have a POST request that could rely on for a longer time inadvertently, you You may need to change the timeoutInterval manually to use a higher value. I was able to set the timeout both lower and higher than 60 seconds for POST, so it does not appear that the 60 second mark represents the minimum timeout limit for this type of request.

+5
Sep 21 '12 at 17:13
source share

This problem has been fixed in iOS5, so now you will not run into this problem. And your code will work fine

-2
May 15 '12 at 2:31
source share



All Articles