Domanda

I'm creating NSMutableRequest and adding data to body. Heres example how I do it:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:stringURL] 
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
                                                       timeoutInterval:230.0];
    NSLog(@"Time out interval: %f", request.timeoutInterval); >> Output: 230

    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];

    NSLog(@"Time out interval: %f", request.timeoutInterval); >> Output: 240
    [request setTimeoutInterval:230];
    NSLog(@"Time out interval: %f", request.timeoutInterval); >> Output: 240

Request timeout after creating it is 230. After I set body It is 240. And after I reset it to 230. It is still 240. Timeout value doesn't change unless I set it bigger?

Anyone has any idea why it is happening? How to make timeout interval less than 240 seconds?

È stato utile?

Soluzione

On the iOS you just cannot specify timeout less then 240s in this way (because iPhone could run on a slow connection). For more details check: https://devforums.apple.com/message/108292#108292

If you're really need shorter timeout, you could use NSTimer. In that case just remember to use asynchronous request, which could be easily canceled.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top