Protocol

URLSessionTaskDelegate

A protocol defining methods that URLSession instances call on their delegates to handle task-level events.

Overview

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

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

Topics

Handling Task Life Cycle Changes

func urlSession(URLSession, task: URLSessionTask, didCompleteWithError: Error?)

Tells the delegate that the task finished transferring data.

Working with Upload Tasks

func urlSession(URLSession, task: URLSessionTask, didSendBodyData: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64)

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

func urlSession(URLSession, task: URLSessionTask, needNewBodyStream: (InputStream?) -> Void)

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

Handling Authentication Challenges

enum URLSession.AuthChallengeDisposition

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

Handling Delayed and Waiting Tasks

enum URLSession.DelayedRequestDisposition

The action to take on a delayed URL session task.

func urlSession(URLSession, taskIsWaitingForConnectivity: URLSessionTask)

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

Collecting Task Metrics

func urlSession(URLSession, task: URLSessionTask, didFinishCollecting: URLSessionTaskMetrics)

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

class URLSessionTaskMetrics

An object encapsulating the metrics for a session task.

See Also

Configuring a Session

var configuration: URLSessionConfiguration

A copy of the configuration object for this session.

var delegate: URLSessionDelegate?

The delegate assigned when this object was created.

protocol URLSessionDelegate

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

var delegateQueue: OperationQueue

The operation queue provided when this object was created.

var sessionDescription: String?

An app-defined descriptive label for the session.