Tasks created kept in background url session

I cannot find any documentation regarding this, and even though it makes kind of sense, I find it hard to understand the reasoning behind the difference between the background/default session configurations.


Consider this playground code:

import Foundation
import PlaygroundSupport

let config = URLSessionConfiguration.background(withIdentifier: "test")
var urlSession = URLSession(configuration: config)
let taskOne = urlSession.dataTask(with: URL(string: "url-one")!) // No resume
let taskTwo = urlSession.dataTask(with: URL(string: "url-two")!) // No resume
let taskThree = urlSession.dataTask(with: URL(string: "url-three")!) // Resume
taskThree.resume()
urlSession.getAllTasks { tasks in
    let count = tasks.count
}
PlaygroundPage.current.needsIndefiniteExecution = true


Line 11 prints 3 when using a background session configuration, and 1 when using the default one.


How come?


This is not the specific case I'm seeing in my code, but this example illustrates the difference that caused an automatic resume bug for me.

Replies

Line 11 prints 3 when using a background session configuration, and 1 when using the default one.

I’d call that a bug. Feel free to file it as such. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"