I have a working background URLSession. I know that upon creating an URLSession with the same session identifier I get a "background URLSession with identifier x already exists"
message.
I know that I can store the session and call .finishTasksAndInvalidate()
on it if needed.
My use case is that if the application terminates, and the user relaunches the application before the background task completes, I need to be able to check if a background URLSession with the same identifier exists, and if it does, restitute the application state with the same handlers (so that I can update a UIProgressView for example).
I have two questions:
- How do I check that a background URLSession with a given identifier already exists?
- Does the AppDelegate completion handler still get called if the application was terminated and relaunched?
Yes it's a single hard-coded identifier.
OK, good.
So then why do you want to check whether the session exists? Just connect up to the session on launch and call getAllTasks(completionHandler:)
to determine if any tasks are running in the session. The existence of the tasks is what matters here, not the session.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"