Reputation: 5184
I'm currently trying to do some debugging on an issue with my background download tasks mysteriously failing during network switches, and found some documentation suggesting that I should be putting multiple tasks into a single background session.
Once you've added more than one background task to a session, how do you determine which task you're looking at? To give an example, lets assume I've downloaded a list of data-entries from the server, and I'm using background session handling to download their associated thumbnails.
When a background task finishes, the session delegate receives a callback to urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL)
.
I can set an identifier on the background session (in fact, you have to); how do you do so with the individual tasks? I want to be able to re-associate a specific task with a specific data object after the app restarts, but there doesn't seem to be any mechanism for doing so.
Am I misunderstanding or missing something in the docs?
Upvotes: 0
Views: 967
Reputation: 125007
NSURLSessionDownloadTask
is a subclass of NSURLSessionTask
, which has a taskIdentifier
property that you can set. Therefore, an NSURLSessionDownloadTask
object is an instance of NSURLSessionTask
, and you can set it's taskIdentifier
property.
Upvotes: 1