<!--
{
  "availability" : [
    "iOS: 9.0.0 - 27.0.0",
    "iPadOS: 9.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.15.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVAssetDownloadDelegate/urlSession(_:assetDownloadTask:didLoad:totalTimeRangesLoaded:timeRangeExpectedToLoad:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(pl)AVAssetDownloadDelegate(im)URLSession:assetDownloadTask:didLoadTimeRange:totalTimeRangesLoaded:timeRangeExpectedToLoad:"
  },
  "title" : "urlSession(_:assetDownloadTask:didLoad:totalTimeRangesLoaded:timeRangeExpectedToLoad:)"
}
-->

# urlSession(_:assetDownloadTask:didLoad:totalTimeRangesLoaded:timeRangeExpectedToLoad:)

Tells the delegate that a download task loaded a new time range.

```
optional func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didLoad timeRange: CMTimeRange, totalTimeRangesLoaded loadedTimeRanges: [NSValue], timeRangeExpectedToLoad: CMTimeRange)
```

## Parameters

`session`

The session the asset download task is on.

`assetDownloadTask`

The download task that loaded a new time range.

`timeRange`

A <doc://com.apple.documentation/documentation/CoreMedia/CMTimeRange> value that indicates the time range the task loaded since the last call to this method.

`loadedTimeRanges`

An array of <doc://com.apple.documentation/documentation/CoreMedia/CMTimeRange> values that indicate the time ranges the task has downloaded so far.

`timeRangeExpectedToLoad`

A <doc://com.apple.documentation/documentation/CoreMedia/CMTimeRange> value that indicates the expected duration of the downloaded asset.

## Discussion

Implement this method to track the download status of an asset. The following example shows how to calculate the percentage complete for the current download.

```swift
func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didLoad timeRange: CMTimeRange, totalTimeRangesLoaded loadedTimeRanges: [NSValue], timeRangeExpectedToLoad: CMTimeRange) {
    var percentageComplete = 0.0
    // Iterate over loaded time ranges
    for value in loadedTimeRanges {
        // Unpack CMTimeRange value
        let loadedTimeRange = value.timeRangeValue
        percentageComplete += loadedTimeRange.duration.seconds / timeRangeExpectedToLoad.duration.seconds
    }
    percentageComplete *= 100
    // Updated interested observers of percentage change
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)