<!--
{
  "availability" : [
    "iOS: 16.1.0 -",
    "iPadOS: 16.1.0 -",
    "macCatalyst: 16.1.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 18.4.0 -",
    "visionOS: 2.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "BackgroundAssets",
  "identifier" : "/documentation/BackgroundAssets/BADownloadManager",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Background Assets"
    ],
    "preciseIdentifier" : "c:objc(cs)BADownloadManager"
  },
  "title" : "BADownloadManager"
}
-->

# BADownloadManager

An object that manages the queue of scheduled asset downloads.

```
class BADownloadManager
```

## Overview

Use [`BADownloadManager`](/documentation/BackgroundAssets/BADownloadManager) to schedule and cancel asset downloads, monitor their progress, and access the queue of pending downloads. You don’t create instances of this class directly; instead, use the [`shared`](/documentation/BackgroundAssets/BADownloadManager/shared) property to access the framework’s singleton that it shares between your app and the app’s extension. Because the download manager is a shared resource, prevent race conditions by using the `withExclusiveControl(_:)` and [`withExclusiveControl(beforeDate:perform:)`](/documentation/BackgroundAssets/BADownloadManager/withExclusiveControl(beforeDate:perform:)) methods to assume absolute control of the manager before you schedule asset downloads or manipulate those already in the manager’s queue. To respond to asset download events and process concluded downloads, create a type that conforms to the [`BADownloadManagerDelegate`](/documentation/BackgroundAssets/BADownloadManagerDelegate) protocol and assign an instance of it to the download manager’s [`delegate`](/documentation/BackgroundAssets/BADownloadManager/delegate) property.

The following example shows how to create an asset download, acquire exclusive control of the shared download manager, and then use the manager to schedule the download:

```swift
let url = URL(string: "https://cdn.example.com/level-resources.zip")!
let request = URLRequest(url: url)
let identifier = "group.com.example.my-game"

// Create an asset download.
let download = BAURLDownload(identifier: "level-resources",
                             request: request,
                             applicationGroupIdentifier: identifier)

// Access the shared download manager.
let manager = BADownloadManager.shared

// Assign the manager's delegate so the framework can notify
// the app of asset download events.
manager.delegate = self

do {
    // Attempt to acquire exclusive control of the manager.
    manager.withExclusiveControl { error in
        // Return immediately if that attempt fails.
        if let error {
            print(error.localizedDescription)
            return
        }
        
        // Use the manager to schedule the asset download.
        try manager.schedule(download)
    }
} catch {
    // Handle the error.
    print(error.localizedDescription)
}
```

## Topics

### Accessing the download manager

[`sharedManager`](/documentation/BackgroundAssets/BADownloadManager/shared)

The download manager that both the app and the extension share.

### Managing downloads

[`-  scheduleDownload:error:`](/documentation/BackgroundAssets/BADownloadManager/scheduleDownload(_:))

Schedules an asset download to execute in the background at a nonspecific time in the future.

[`-  startForegroundDownload:error:`](/documentation/BackgroundAssets/BADownloadManager/startForegroundDownload(_:))

Schedules an asset download that executes immediately in the foreground.

[`-  cancelDownload:error:`](/documentation/BackgroundAssets/BADownloadManager/cancel(_:))

Cancels an asset download.

### Monitoring downloads

[`delegate`](/documentation/BackgroundAssets/BADownloadManager/delegate)

The download manager’s delegate.

[`BADownloadManagerDelegate`](/documentation/BackgroundAssets/BADownloadManagerDelegate)

An interface for reacting to asset download events and processing concluded downloads.

### Fetching in-progress downloads

[`-  fetchCurrentDownloads:`](/documentation/BackgroundAssets/BADownloadManager/fetchCurrentDownloads())

[`-  fetchCurrentDownloadsWithCompletionHandler:`](/documentation/BackgroundAssets/BADownloadManager/fetchCurrentDownloads(completionHandler:))

Fetches the contents of the manager’s download queue.

### Synchronizing manager access

[`-  performWithExclusiveControlBeforeDate:performHandler:`](/documentation/BackgroundAssets/BADownloadManager/withExclusiveControl(beforeDate:perform:))

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)