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)
}
}
}
}