I'm using URLSessionDownloadTask to download a large ZIP file in my app. However, users may close the app while the download is in progress, especially when dealing with a single large file. In my research, I've found solutions for pausing or stopping downloads with provided buttons or functions, but I want the ability to resume downloading from the previous progress when users relaunch the app. Is this possible with URLSessionDownloadTask, or should I consider using a different library? (Note: I'm not referring to resuming downloads in the background after the app has been killed.)
self.fileDownloadUrl = "www.example.com"
var identifier: String = "com.example.app"
if let downloadUrl = self.fileDownloadUrl {
let config = URLSessionConfiguration.background(withIdentifier: identifier)
self.session = URLSession.init(configuration: config, delegate: self, delegateQueue: nil)
let fileUrl = URL(string: downloadUrl)!
let request = URLRequest(url: fileUrl)
self.task = self.session!.downloadTask(with: request)
return
} else {
// Error
return self.unownedErrorPopUp.showAnimation()
}
See the docs for URLSessionConfiguration.background(withIdentifier:)
So if the user terminates the app, your downloads will be cancelled. I'm not sure what you mean by "...a large volume can cause users to accidentally shut down the app midway." How would the user shut down the app? If they shut it down from the multitasking screen (swiping up on the app to kill it) then your background download(s) will be terminated.