I think this library would be helpful - https://github.com/AFNetworking/AFNetworking
This library is a wrapper for Apple's API and has async tasks handled correctly. The example is shown here by Matt Thompson
How to download a file and save it to the documents directory with AFNetworking?
how to use API for downloading a resource from a url in background. This is just one example but most of them work in a similar manner to perform task in background without blocking Main UI thread
Eg :-
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"..."]];
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"filename"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];