In my iOS download manager
RCDownload is an object that holds title, url, download state and resume data location of a download
I have a block variable called defaultSession which looks like this:
lazy var defaultSession: URLSession = {
let configuration = URLSessionConfiguration.background(withIdentifier: "RCBackgroundDownloader")
configuration.isDiscretionary = false
configuration.sessionSendsLaunchEvents = true
let session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
return session
}()
My app is able to pause and resume downloads
And my resume function looks like this:
func resume(download: RCDownload) {
var data: Data!
do {
data = try Data(contentsOf: download.getResumeDataURL())
} catch {}
download.downloadState = downloadStatus.downloading
if data != nil {
download.downloadTask = self.defaultSession.downloadTask(withResumeData: data)
download.downloadTask?.resume()
} else {
download.downloadTask = self.defaultSession.downloadTask(with: download.downloadURL)
download.downloadTask?.resume()
}
}
This code works perfectly on iOS 9 but on iOS 10 it does not resume when I kill my app and reopen it no errors are appearing though (reminder: it is working perfectly on iOS 9), I am confused is there any explanation ?