Aside from the obvious capability differences, NSURLDownload and NSURLConnection have two more subtle, yet significant, differences in behavior.
NSURLConnection provides support for caching of a response from a server in the application’s NSURLCache storage. It also provides the delegate method connection:shouldCacheResponse: which allows an application to customize the cached response.
NSURLDownload does not cache responses in the application’s NSURLCache storage, nor does it provide a delegate method to enable this behavior.
One of the significant differences between NSURLConnection and NSURLDownload is the handling of requests for non-existent URLs when web server has be configured to return an alternate page in response to an error.
When using NSURLConnection the default behavior is to allow the redirect and return the contents of the redirected URL, instead of returning an error. If an attempt is made to download the same URL using NSURLDownload, an error is returned indicating that the file has not been found.
An NSURLConnection delegate can mimic the NSURLDownload behavior by implementing the connection:willSendRequest:responseRequest: method, and examining the provided NSURLResponse. If the response is an NSHTTPURLResponse object, and the statusCode is 4xx or 5xx, then the server is attempting to redirect to an alternate error page. The delegate can prevent this by returning nil.
Last updated: 2009-08-14