Alamofire: cache large files uploaded to the Documents folder

I am using this piece of code to download MP3 files to my document directory:

let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
Alamofire.download(theUrl!, to:destination).response { response in
    // stuff
}.downloadProgress { progress in
    // Stuff
}

      

The file downloads are fine, but if I close the app and run it again the download will restart from 0. What I want is for the file to be cached and checked out right away. My understanding of Alamofire is that the file is downloaded to a temp folder and then moved to the Documents folder, is that what is not calling the cache?

Thank you so much

+3


source to share


1 answer


Please check the following links:
1. https://github.com/Alamofire/Alamofire/issues/1104
2. https://github.com/Alamofire/Alamofire#resuming-a-download
3. fooobar.com/questions/ 161544 / ...

In short:
You need to use the request.cancel () API to generate the resumeData before your application exits.
Then you use the resume API with resumeData to resume the request when you restart your application.
There is no guarantee that it will always work. If it fails, it will still restart from 0.



There was an issue with iOS 10 mentioned in link (2) above preventing it from working correctly. But an update on StackOverflow (link 3) has a report that it was fixed in iOS 10.2

+7


source







All Articles