AVAssetDownloadDelegate methods are not called when resumed

I use AVAggregateAssetDownloadTask to download video contents . pause , resume works fine in the normal flow . AVAssetDownloadDelegate methods are not called when the task is resumed on app relaunch. Steps:

  • download content
  • quit app when download is in progress
  • relaunch app
  • create session and get all tasks and resume tasks
  • delegates not called

I have confirmed that session and tasks are not nil .

  func restorePersistenceManager() {
    guard !didRestorePersistenceManager else { return }
    didRestorePersistenceManager = true
    // Grab all the tasks associated with the assetDownloadURLSession
    assetDownloadURLSession.getAllTasks { tasksArray in
      let downloadsArray = DownloadManager.shared.getAllDownloadedAssets()
      // For each task, restore the state in the app by recreating Asset structs and reusing existing AVURLAsset objects.
      for task in tasksArray {
        guard let assetDownloadTask = task as? AVAggregateAssetDownloadTask, let assetName = task.taskDescription else { break }

         let downloadAsset = downloadsArray.filter {$0.stream.name == assetName}
        if downloadAsset.count > 0 {
          let urlAsset = assetDownloadTask.urlAsset
          var asset = Asset(stream: (downloadAsset.first?.stream)!, urlAsset: urlAsset)
          self.activeDownloadsMap[assetDownloadTask] = asset
          StreamManager.shared.setStream(value: (downloadAsset.first?.stream)!)
          self.resumeDownload(for: &asset)
        }         
      }

    }
  }

On restoring the task, do you need to re-assign it's delegate?

restorePersistenceManager() is present in singleton class . So the session gets created in init method and delegate get set here

 override  init() {
super.init()

        bitrate = SettingsManager.shared.downloadQuailty ?? 9728000.0

        // streamManager = StreamManager()

        // Create the configuration for the AVAssetDownloadURLSession.

        let backgroundConfiguration = URLSessionConfiguration.background(withIdentifier: "unique-Identifier")

        // Create the AVAssetDownloadURLSession using the configuration.

        assetDownloadURLSession =

            AVAssetDownloadURLSession(configuration: backgroundConfiguration,

                                      assetDownloadDelegate: self, delegateQueue: OperationQueue.main)

    }
AVAssetDownloadDelegate methods are not called when resumed
 
 
Q