Raffi
Raffi

Reputation: 757

Why is URLSession 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)
            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 ?

Upvotes: 0

Views: 798

Answers (1)

Munahil
Munahil

Reputation: 2419

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.

Upvotes: 2

Related Questions