Re: Reuse and lifetime of NSURLSessions
Re: Reuse and lifetime of NSURLSessions
- Subject: Re: Reuse and lifetime of NSURLSessions
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Wed, 28 Jan 2015 09:18:48 +0000
On 28 Jan 2015, at 01:50, Greg Robbins <email@hidden> wrote:
> What's an appropriate granularity for reusing an NSURLSession object?
It's mostly up to you. The only approach that I specifically advise against is "one session per task", which is needlessly wasteful. Sessions are supposed to be relatively long-lived objects. Which means...
> 2. Is there value to reusing a session for as long as an app is running, or to invalidating a session when an app is not making network requests?
It's perfectly reasonable to create a session when you app launches and keep it around for the lifetime of your app.
* * *
Off the top of my head I can see three really good reasons for using multiple sessions:
o You have multiple entities within the process and you want their requests to be separate. The obvious use case here is for frameworks, where the framework developer wants their requests to be separate from those requests issued by the app and by other frameworks.
o You have requests with very different characteristics, characteristics that are controlled by the session configuration. For example, you want some requests to use the system proxy settings (if any) and some to use your custom proxy.
o You're using background session support.
I'm sure there are other good reasons as well.
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
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