Protocol

NSURLSessionDataDelegate

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

Declaration

@protocol NSURLSessionDataDelegate

Overview

Your session delegate should also implement the methods in the NSURLSessionTaskDelegate protocol to handle task-level events that are common to all task types, and methods in the NSURLSessionDelegate protocol to handle session-level events.

Topics

Handling Task Life Cycle Changes

- URLSession:dataTask:didReceiveResponse:completionHandler:

Tells the delegate that the data task received the initial reply (headers) from the server.

NSURLSessionResponseDisposition

Constants indicating how a data or upload session should proceed after receiving the initial headers.

- URLSession:dataTask:didBecomeDownloadTask:

Tells the delegate that the data task was changed to a download task.

- URLSession:dataTask:didBecomeStreamTask:

Tells the delegate that the data task was changed to a stream task.

Receiving Data

- URLSession:dataTask:didReceiveData:

Tells the delegate that the data task has received some of the expected data.

Handling Caching

- URLSession:dataTask:willCacheResponse:completionHandler:

Asks the delegate whether the data (or upload) task should store the response in the cache.

Relationships

See Also

Adding Data Tasks to a Session

- dataTaskWithURL:

Creates a task that retrieves the contents of the specified URL.

- dataTaskWithURL:completionHandler:

Creates a task that retrieves the contents of the specified URL, then calls a handler upon completion.

- dataTaskWithRequest:

Creates a task that retrieves the contents of a URL based on the specified URL request object.

- dataTaskWithRequest:completionHandler:

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

NSURLSessionDataTask

A URL session task that returns downloaded data directly to the app in memory.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software