Class

NSURLSessionDownloadTask

A URL session task that stores downloaded data to file.

Declaration

@interface NSURLSessionDownloadTask : NSURLSessionTask

Overview

An NSURLSessionDownloadTask is a concrete subclass of NSURLSessionTask. Most of the methods associated with this class are documented in NSURLSessionTask.

Download tasks directly write the server’s response data to a temporary file, providing your app with progress updates as data arrives from the server. When you use download tasks in background sessions, these downloads continue even when your app is suspended or is otherwise not running.

You can pause (cancel) download tasks and resume them later (assuming the server supports doing so). You can also resume downloads that failed because of network connectivity problems.

Download Delegate Behavior

When you use a download task, your delegate receives several callbacks unique to download scenarios.

Table 1

NSError Codes for Server-Side Download Errors

HTTPS Status

NSError code

401 Unauthorized

NSURLErrorUserAuthenticationRequired

403 Unauthorized

NSURLErrorNoPermissionsToReadFile

407 Proxy Authentication Required

NSURLErrorUserAuthenticationRequired

(other)

NSURLErrorFileDoesNotExist

Topics

Canceling a Download

- cancelByProducingResumeData:

Cancels a download and calls a callback with resume data for later use.

Initializers

- initDeprecated

Type Methods

+ newDeprecated

Relationships

Inherits From

See Also

Adding Download Tasks to a Session

- downloadTaskWithURL:

Creates a download task that retrieves the contents of the specified URL and saves the results to a file.

- downloadTaskWithURL:completionHandler:

Creates a download task that retrieves the contents of the specified URL, saves the results to a file, and calls a handler upon completion.

- downloadTaskWithRequest:

Creates a download task that retrieves the contents of a URL based on the specified URL request object and saves the results to a file.

- downloadTaskWithRequest:completionHandler:

Creates a download task that retrieves the contents of a URL based on the specified URL request object, saves the results to a file, and calls a handler upon completion.

- downloadTaskWithResumeData:

Creates a download task to resume a previously canceled or failed download.

- downloadTaskWithResumeData:completionHandler:

Creates a download task to resume a previously canceled or failed download and calls a handler upon completion.

NSURLSessionDownloadDelegate

A protocol defining methods that URL session instances call on their delegates to handle task-level events specific to download tasks.