I've been looking at this issue for a while now and can't seem to find the solution anywhere on google and the ios documentation.
My app sends 3 asynch requests. The first two are called from the main thread, and the last is called from another thread, in this order. They are sent one after the other but with relatively little delay between them.
//build the request url
NSURL *defaultResultsURL = [self getDefaultResultsURL];
//create the request
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:defaultResultsURL
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:MAX_TIMEOUT_BACKEND];
//invoke requestAllDefaultResults for all elements - invoke on main thread
defualtsResponse = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
[defualtsResponse scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[defualtsResponse start];
The problem is that sometimes, not all the times and only on one of the iPhones I'm testing, and only when the app is first installed, the first request returns with timeout error, in less than 5 seconds, which is the specified request timeout.
I've checked the backend server, and I see that all three requests are received and responses are sent back.
I did try to check if the current thread is running before sending the requests using
if([NSThread isMainThread]){
defualtsResponse = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
But I'm still getting timeout errors.