• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Associating context with background NSURLSession tasks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Associating context with background NSURLSession tasks
      • From: Greg Robbins <email@hidden>
References: 
 >Associating context with background NSURLSession tasks (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: NSURLSession and cellular access
  • Next by Date: Re: Associating context with background NSURLSession tasks
  • Previous by thread: Re: Associating context with background NSURLSession tasks
  • Next by thread: Re: Associating context with background NSURLSession tasks
  • Index(es):
    • Date
    • Thread