Guy Kahlon
Guy Kahlon

Reputation: 4520

NSURLConnection in background Thread

I want to load something (big) asynchronously in a background thread (use with NSOperation).

after many searches I came across two options: The first is use with:

CFRunLoopRun()

which explain wonderful in this link : http://www.russellj.co.uk/blog/2011/07/09/nsurlconnection-in-a-background-thread/

the second is use with:

NSPort* port = [NSPort port];
NSRunLoop* rl = [NSRunLoop currentRunLoop]; // Get the runloop
rl addPort:port forMode:NSDefaultRunLoopMode];

which explain good in this link : http://www.cocoaintheshell.com/2011/04/nsurlconnection-synchronous-asynchronous/

I realy want to use with the first option because is very elegant and readability. but I'm afraid I do not really understand the differences between the two approaches.

Thanks for help.

Upvotes: 1

Views: 1749

Answers (1)

Paul Dardeau
Paul Dardeau

Reputation: 2619

I'd recommend the following built-in method if it suits your needs. It's easy to use and is reliable.

  • (void)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue )queue completionHandler:(void (^)(NSURLResponse, NSData*, NSError*))handler

Upvotes: 1

Related Questions