I'm trying to implement a seemingly common feature in my app: to upload files in the background. I run such tasks by calling -[UIApplication beginBackgroundTaskWithExpirationHandler:]
, so those tasks are each identified by a UIBackgroundTaskIdentifier
.
Please take a look at the diagram below. Orange boxes are problem points for which I can't seem to find any answer.
Here are the questions for which I seek guidance:
Is it possible to get a list of running tasks that same app initiated in a previous session?
Is it possible to associate some kind of meta data, such as a URL string, with a background task, so we can know which task is uploading which file?
Are you using
NSURLConnection
orNSURLSession
?If
NSURLSession
, you can usegetTasksWithCompletionHandler
. You can also use a backgroundNSURLSessionConfiguration
, rather than relying onbeginBackgroundTaskWithExpirationHandler
. And it terms of keeping track of the requests, you can retrieve theoriginalRequest
from the task (and retrieve the URL from that), or update your model with thetaskIdentifier
for theNSURLSessionTask
, and cross reference requests in your own model that way.