Tells the delegate that the data task received the initial reply (headers) from the server.
- iOS 7.0+
- macOS 10.9+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
The session containing the data task that received an initial reply.
The data task that received an initial reply.
A URL response object populated with headers.
A completion handler that your code calls to continue a transfer, passing a
URLSessionconstant to indicate whether the transfer should continue as a data task or should become a download task.
If you pass
URLSession, the task continues as a data task.
.Response Disposition .allow
If you pass
URLSession, the task is canceled.
.Response Disposition .cancel
Implementing this method is optional unless you need to cancel the transfer or convert it to a download task when the response headers are first received. If you don’t provide this delegate method, the session always allows the task to continue.
You also implement this method if you need to support the fairly 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, followed by one or more calls to
url with the contents of that part.
Each time the
url method is called for a part, collect the data received for the previous part (if any) and process the data as needed for your application. This processing can include storing the data to the filesystem, parsing it into custom types, or displaying it to the user. Next, begin receiving the next part by calling the completion handler with the
URLSession constant. Finally, if you have also implemented
url, the session will call it after sending all the data for the last part.