Raffi Raffi - 1 year ago 97
iOS Question

Why is URLSession is not resuming on iOS 10?

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)
} else {
download.downloadTask = self.defaultSession.downloadTask(with: download.downloadURL)


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 ?

Answer Source

The bug is in iOS 10, Apple has to fix it. They have fixed it for 10.2 version though, according to this thread on Apple's forum.

You can also look into this Stackoverflow's post. They have provided the solution with details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download