Protocol

NSURLSessionTaskDelegate

A protocol that defines methods that URL session instances call on their delegates to handle task-level events.

Declaration

@protocol NSURLSessionTaskDelegate

Overview

If you’re using download tasks, also implement the methods in the NSURLSessionDownloadDelegate protocol.

If you’re using data or upload tasks, also implement the methods in the NSURLSessionDataDelegate protocol.

Topics

Handling Task Life Cycle Changes

- URLSession:task:didCompleteWithError:

Tells the delegate that the task finished transferring data.

Handling Redirects

- URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:

Tells the delegate that the remote server requested an HTTP redirect.

Working with Upload Tasks

- URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:

Periodically informs the delegate of the progress of sending body content to the server.

- URLSession:task:needNewBodyStream:

Tells the delegate when a task requires a new request body stream to send to the remote server.

Handling Authentication Challenges

- URLSession:task:didReceiveChallenge:completionHandler:

Requests credentials from the delegate in response to an authentication request from the remote server.

NSURLSessionAuthChallengeDisposition

Constants passed by session or task delegates to the provided continuation block in response to an authentication challenge.

Handling Delayed and Waiting Tasks

- URLSession:task:willBeginDelayedRequest:completionHandler:

Tells the delegate that a delayed URL session task will now begin loading.

NSURLSessionDelayedRequestDisposition

The action to take on a delayed URL session task.

- URLSession:taskIsWaitingForConnectivity:

Tells the delegate that the task is waiting until suitable connectivity is available before beginning the network load.

Collecting Task Metrics

- URLSession:task:didFinishCollectingMetrics:

Tells the delegate that the session finished collecting metrics for the task.

NSURLSessionTaskMetrics

An object encapsulating the metrics for a session task.

See Also

Working with a Delegate

delegate

The delegate assigned when this object was created.

NSURLSessionDelegate

A protocol that defines methods that URL session instances call on their delegates to handle session-level events, like session life cycle changes.

delegateQueue

The operation queue provided when this object was created.