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.

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. In addition to the methods defined in this protocol, most delegates should also implement some or all of the methods in the URLSessionTaskDelegate, URLSessionDataDelegate, and URLSessionDownloadDelegate protocols to handle task-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.

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