Protocol

URLSessionTaskDelegate

The NSURLSessionTaskDelegate protocol defines the task-specific delegate methods that you should implement when working with any type of URLSession task.

Overview

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

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

Topics

Delegate Methods

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.

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

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

class URLSessionTaskMetrics

An NSURLSessionTaskMetrics object encapsulates the metrics for a session task. Each object contains the taskInterval and redirectCount, as well as metrics for each request / response transaction made during the execution of the task.

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

Tells the delegate that the task finished transferring data.

func urlSession(URLSession, taskIsWaitingForConnectivity: URLSessionTask)

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

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

The NSURLSessionDelegate protocol describes the methods that URLSession objects call on their delegates to handle session-level events.

var delegateQueue: OperationQueue

The operation queue provided when this object was created.

var sessionDescription: String?

An app-defined descriptive label for the session.