Delete AVAssetDownloadTask all not downloaded files

398 views Asked by At

I need to delete all files that AVAssetDownloadTask didn't manage to download while the app was running. I want to do this after the app has received the UIApplication.willTerminateNotification.

I tried cancel of all AVAssetDownloadTasks, but AVAssetDownloadDelegate urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL) is not being called at the moment. I wanted to get all files' location urls.

If there are other ways to do this?

2

There are 2 answers

0
MGY On BEST ANSWER

Will Download to Location

You can track final location with this delegate:

optional func urlSession(_ session: URLSession, 
        aggregateAssetDownloadTask: AVAggregateAssetDownloadTask, 
           willDownloadTo location: URL)

Tells the delegate the final location of the asset when the download completes.

This delegate callback should only be used to save the location URL somewhere in your application.

Any additional work should be done in:

optional func urlSession(_ session: URLSession, 
                              task: URLSessionTask, 
        didCompleteWithError error: Error?)

Here is the official documentation pages:

0
M. LeRouge On

If you call -cancel on AVAssetDownloadTask, -didFinishDownloadingTo location: immediately fires.