gebirgsbärbel
gebirgsbärbel

Reputation: 2397

URLSessionDownloadDelegate method didWriteData not called after app was in background

In my app I want to download big files. As such, I want to display download progress to the user. For this I implemented the URLSessionDownloadDelegate.

This works great until the app goes to the background. When the user then reopens the app didWriteData is not called. However didFinishDownloadingTo is still called. Hence it is not a problem with the delegate itself.

Some other developers reported similar issues in https://forums.developer.apple.com/message/229215#229215.

However, so far there seem to be no solutions or workarounds to this issue. Did anyone here find any workaround? If no, what could I use instead of SessionDownloadTask?

Upvotes: 2

Views: 523

Answers (1)

gebirgsbärbel
gebirgsbärbel

Reputation: 2397

This seems to be a bug in iOS12. As a workaround I resume all the download tasks once the application became active again. Like this:

private(set) var session: URLSession?

func applicationDidBecomeActive(_ application: UIApplication) {
    session?.getAllTasks(completionHandler: { tasks in
        for task in tasks {
            task.resume()
        }
    })
}

Upvotes: 3

Related Questions