Since you're creating a connection to be scheduled in a loop and started later, make sure to use the rendition of initWithRequest
with the startImmediately
parameter set to NO
. Right now, you're starting the connection twice. And, more significantly, you're starting it before you scheduled it in the main run loop.
To remedy this, specify startImmediately
as NO
:
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
[conn scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[conn start];
Having said that, I see no need to dispatch this code to the background queue at all (because initWithRequest
runs asynchronously and will have no discernible impact on the app performance). The only time I use the above pattern is when I'm wrapping my NSURLConnection
requests in some custom NSOperation
subclass (in which case, the above pattern is very useful). But in this case, it is unnecessary.