NSURLConnection with delegate vs initWithContentsOfURL: with Grand Central Dispatch
I am writing an application which downloads very much JSON data from the internet. My app needs to parse this JSON data and afterwards return the retrieved objects to a self-made delegate.
Now I was wondering if I could b开发者_C百科etter use NSURLConnection or a combination of Grand Central Dispatch's dispatch_async
with initWithContentsOfURL:
(using GCD to prevent hanging).
Using Grand Central Dispatch is much easier to implement, especially because I don't need delegates nor NSMutableData nor all other variables that are used temporarily. But of course, everything with pros has its cons.
What are the advantages of NSURLConnection over initWithContentsOfURL
with GCD?
- You can target iOS 3.x.
- You can use a customized NSURLRequest that, e.g., asks for the results of an HTTP POST—the NSData factory only does basic GET when passed an HTTP URL.
- You can track the download's progress with your NSURLConnection delegate.
That's it off the top of my head. :)
精彩评论