AVAssetDownloadURLSession
A URL session that creates and manages asset download tasks.
Declaration
class AVAssetDownloadURLSessionOverview
Create an AVAssetDownloadURLSession by calling init(configuration:assetDownloadDelegate:delegateQueue:) with a background URLSessionConfiguration. The background configuration supports reliable downloading while the app is in a suspended state.
Background sessions persist across app launches. The system manages downloads out-of-process so they continue while your app is in a suspended state. If the system terminates your app while downloads are in progress, it relaunches the app and calls application(_:handleEventsForBackgroundURLSession:completionHandler:) with the session identifier. Recreate the AVAssetDownloadURLSession using the same background configuration identifier to reconnect to the running session and receive pending delegate callbacks. Call the provided completion handler after all callbacks finish. If a person force-quits your app, the system cancels all active downloads and doesn’t relaunch the app.
Mark the background session configuration as discretionary to let the system defer downloads until network and battery conditions are favorable. You can only start a non-discretionary download task while your app is in the foreground. Reserve non-discretionary sessions for downloads that a person explicitly starts. Use a discretionary session for opportunistic downloads that happen without a person’s direct involvement.
Assign an AVAssetDownloadDelegate to the session to receive download progress, media-selection resolution, and completion callbacks for every download task the session creates.
Topics
Creating a download session
Creating download tasks
makeAssetDownloadTask(downloadConfiguration:)AVAssetDownloadConfigurationmakeAssetDownloadTask(asset:assetTitle:assetArtworkData:options:)aggregateAssetDownloadTask(with:mediaSelections:assetTitle:assetArtworkData:options:)makeAssetDownloadTask(asset:destinationURL:options:)