dispatch_async NSURLConnection - download don't start
I'm trying to download information in background from a url. I've read
about GCD, Runloops and threads and decided that dispatc_async is my way
to go. After receiving data I aalso want to update the gui. But... the
NSUrlConnection don't seem to start at all. The delegate don't receive any
calls. I'v used this NSUrlRequest and NSUrlConnection in a synchronous way
and the delegate got the data excpected.
Here is my code, a method in a viewcontroller;
- (void)dispatch: (NSURLRequest *) pRequest respondTo: (VivaQuery *)
pQuery {
dispatch_queue_t downloadQueue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(downloadQueue, ^{
NSURLConnection *tConnectionResponse =[[NSURLConnection alloc]
initWithRequest: pRequest delegate: pQuery];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Got to main thread.");
[pQuery requestEnd]; // Will update gui, i e aUIView
setNeedsDisplay
});
});
}
Anyone got an idea? Thanks in advance.
Kind regards, Jan Gifvars Stockholm
No comments:
Post a Comment