iOS Developer Library

Developer

Foundation Framework Reference NSURLSessionDownloadTask Class Reference

Options
Deployment Target:

On This Page
Language:

NSURLSessionDownloadTask

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

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in iOS 7.0 and later.
  • Cancels a download and calls a callback with resume data for later use.

    Declaration

    Swift

    func cancelByProducingResumeData(_ completionHandler: (NSData!) -> Void)

    Objective-C

    - (void)cancelByProducingResumeData:(void (^)(NSData *resumeData))completionHandler

    Parameters

    completionHandler

    A completion handler that is called when the download has been successfully canceled.

    If the download is resumable, the completion handler is provided with a resumeData object. Your app can later pass this object to a session’s downloadTaskWithResumeData: or downloadTaskWithResumeData:completionHandler: method to create a new task that resumes the download where it left off.

    Discussion

    A download can be resumed only if the following conditions are met:

    • The resource has not changed since you first requested it

    • The task is an HTTP or HTTPS GET request

    • The server provides either the ETag or Last-Modified header (or both) in its response

    • The server supports byte-range requests

    • The temporary file hasn’t been deleted by the system in response to disk space pressure

    Import Statement

    import Foundation

    Availability

    Available in iOS 7.0 and later.