Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

NSURLDownload and NSURLConnection Differences

Aside from the obvious capability differences, NSURLDownload and NSURLConnection have two more subtle, yet significant, differences in behavior.

Contents:

Response Caching
Handling of Non-existent URLs


Response Caching

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.

Handling of Non-existent URLs

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.



< Previous PageNext Page > Hide TOC


Last updated: 2008-05-06




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice