Instance Method

urlSession(_:dataTask:didReceive:completionHandler:)

Tells the delegate that the data task received the initial reply (headers) from the server.

Declaration

optional func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void)

Parameters

session

The session containing the data task that received an initial reply.

dataTask

The data task that received an initial reply.

response

A URL response object populated with headers.

completionHandler

A completion handler that your code calls to continue the transfer, passing a constant to indicate whether the transfer should continue as a data task or should become a download task.

Discussion

This method is optional unless you need to support the (relatively obscure) multipart/x-mixed-replace content type. With that content type, the server sends a series of parts, each of which is intended to replace the previous part. The session calls this method at the beginning of each part, and you should then display, discard, or otherwise process the previous part, as appropriate.

If you do not provide this delegate method, the session always allows the task to continue.