NSURLConnectionDownloadDelegate Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in iOS 5.0 and later.
Declared in
NSURLConnection.h

Overview

The NSURLConnectionDownloadDelegate protocol describes methods that should be implemented by the delegate of instances of NSURLConnection created using Newsstand Kit’s downloadWithDelegate: method. The methods in this protocol provide progress information about the download of a URL asset and, when downloading concludes, provide a file URL where the downloaded file can be accessed.

In addition to the methods described in this protocol, an NSURLConnection delegate should also implement the methods described in the NSURLConnectionDelegate protocol.

Tasks

Managing Downloads of URL Assets

Instance Methods

connection:didWriteData:totalBytesWritten:expectedTotalBytes:

Sent to the delegate to deliver progress information for a download of a URL asset to a destination file.

- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes
Parameters
connection

The URL connection object downloading the asset.

bytesWritten

The number of bytes written since the last call of this method.

totalBytesWritten

The total number of bytes of the downloading asset that have been written to the file.

expectedTotalBytes

The total number of bytes of the URL asset once it is completely downloaded and written to a file. This parameter can be zero if the total number of bytes is not known.

Discussion

This method is invoked repeatedly during the download of a URL asset to the destination file. The delegate typically uses the values of the three “bytes” parameters to update a progress indicator in the application’s user interface.

Availability
  • Available in iOS 5.0 and later.
Declared In
NSURLConnection.h

connectionDidFinishDownloading:destinationURL:

Sent to the delegate when the URL connection has successfully downloaded the URL asset to a destination file.

- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *)destinationURL
Parameters
connection

The URL connection object that downloaded the asset.

destinationURL

A file URL specifying a destination in the file system. For iOS applications, this is a location in the application sandbox.

Discussion

This method will be called once after a successful download. The file downloaded to destinationURL is guaranteed to exist there only for the duration of this method implementation; the delegate should copy or move the file to a more persistent and appropriate location.

Availability
  • Available in iOS 5.0 and later.
Declared In
NSURLConnection.h

connectionDidResumeDownloading:totalBytesWritten:expectedTotalBytes:

Sent to the delegate when an URL connection resumes downloading a URL asset that was earlier suspended.

- (void)connectionDidResumeDownloading:(NSURLConnection *)connection totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes
Parameters
connection

The URL connection object downloading the asset.

totalBytesWritten

The total number of bytes of the downloading asset that have been written to the destination file.

expectedTotalBytes

The total number of bytes of the URL asset once it is completely downloaded and written to a file.

Discussion

This method is invoked once a suspended download of a URL asset resumes downloading. In response, the delegate can display a progress indicator, setting the initial value of the indicator to where it was when downloading was suspended. After the URL-connection object sends this message, it sends one or more connection:didWriteData:totalBytesWritten:expectedTotalBytes: to the delegate until the download concludes.

Availability
  • Available in iOS 5.0 and later.
Declared In
NSURLConnection.h