Re: Associating context with background NSURLSession tasks
Re: Associating context with background NSURLSession tasks
- Subject: Re: Associating context with background NSURLSession tasks
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Wed, 11 Feb 2015 11:11:33 +0000
On 10 Feb 2015, at 01:37, Rick Mann <email@hidden> wrote:
> It seems that the NSURLSession API is missing a very important piece: a mechanism for associating context with a background task.
I solve this problem by using the quite-obscure +setProperty:forKey:inRequest: and +propertyForKey:inRequest: methods on NSURLProtocol. I create a unique ID for my request, assign that to a property on the request, and then create the task from that. As long as you use a property that supports NSSecureCoding on both sides of the 'wire' [1], that property persists with the task across relaunches of your app. To keep things simple I typically use a string.
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
[1] That is, both your app and the NSURLSession background session daemon.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden