URLSessionTaskDelegate
A protocol that defines methods that URL session instances call on their delegates to handle task-level events.
Declaration
protocol URLSessionTaskDelegate : URLSessionDelegateMentioned in
Overview
You use this protocol in one of two ways, depending on how you use a URLSession:
If you create tasks with Swift’s
async-awaitsyntax, using methods like bytes(for:delegate:) and data(for:delegate:), you pass adelegateargument of this type. The delegate receives callbacks for things like task progress, while the call point awaits the completion of the task.If you add tasks to the session with methods like dataTask(with:) and downloadTask(with:), then you implement this protocol’s methods in a delegate you set on the session. This session delegate may also implement other protocols as appropriate, like URLSessionDownloadDelegate and URLSessionDataDelegate. You can also assign a delegate of this type directly to the task to intercept callbacks before the task delivers them to the session’s delegate.
Topics
Handling task life cycle changes
Handling redirects
Working with upload tasks
urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:)urlSession(_:task:needNewBodyStream:)
Handling authentication challenges
Handling delayed and waiting tasks
urlSession(_:task:willBeginDelayedRequest:completionHandler:)URLSession.DelayedRequestDispositionurlSession(_:taskIsWaitingForConnectivity:)