Instance Method

urlSession(_:task:needNewBodyStream:)

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

Declaration

optional func urlSession(_ session: URLSession, task: URLSessionTask, needNewBodyStream completionHandler: @escaping (InputStream?) -> Void)

Parameters

session

The session containing the task that needs a new body stream.

task

The task that needs a new body stream.

completionHandler

A completion handler that your delegate method should call with the new body stream.

Discussion

This delegate method is called under two circumstances:

  • To provide the initial request body stream if the task was created with uploadTask(withStreamedRequest:)

  • To provide a replacement request body stream if the task needs to resend a request that has a body stream because of an authentication challenge or other recoverable server error.

See Also

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, 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.