Contents

URLSessionTaskDelegate

A protocol that defines methods that URL session instances call on their delegates to handle task-level events.

Declaration

protocol URLSessionTaskDelegate : URLSessionDelegate

Mentioned 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-await syntax, using methods like bytes(for:delegate:) and data(for:delegate:), you pass a delegate argument 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

Handling authentication challenges

Handling delayed and waiting tasks

Collecting task metrics

Instance Methods

See Also

Working with a delegate