Contents

AVAssetDownloadTask

A URL session task that downloads a remote asset to the device for offline playback.

Declaration

class AVAssetDownloadTask

Overview

You create instances of this class by calling makeAssetDownloadTask(downloadConfiguration:) on the download session.

To play an asset while its download is in progress, reuse the AVURLAsset you supplied to the download configuration. The asset reads locally cached segments during concurrent playback when the streaming variant matches the downloading variant.

Adopt the AVAssetDownloadDelegate protocol to receive progress and completion callbacks. Use the inherited progress property for numeric download progress updates. The delegate method urlSession(_:assetDownloadTask:willDownloadTo:) provides the local file URL where the system stores the asset.

To augment an existing download, initialize a new task with an AVURLAsset whose URL references the downloaded asset on disk. For example, you can add media selections that you didn’t include in the original download.

Live Activity

To control how the system schedules downloads, set the isDiscretionary property on the URLSessionConfiguration you pass when creating the AVAssetDownloadURLSession. Non-discretionary downloads start as soon as possible. The system defers discretionary downloads until conditions like network and battery state are favorable, and runs them silently in the background.

On supported platforms, a non-discretionary download displays a Live Activity on the Lock Screen and in the Dynamic Island that shows real-time download progress. Discretionary downloads don’t display a Live Activity.

When your app has multiple active downloads, the system aggregates them into a single Live Activity that shows combined progress. For a single active download, the activity title displays the asset title.

If any downloads in the group fail, the Live Activity transitions to a failure state after all downloads finish. A person can also cancel all active and queued downloads for your app directly from the Live Activity, which causes the tasks to fail with NSUserCancelledError in the NSCocoaErrorDomain domain.

The Live Activity doesn’t reflect download tasks until you resume them. If you resume a task while your app runs in the background, the system might demote it to discretionary. The system queues downloads in the order you resume them.

Swift subclasses of this type must conform to Sendable.

Topics

Accessing task information

See Also

Asset downloading