iosnsurlsessionnsurlsessionconfiguration

Can NSURLSession objects be created multiple times with different configurations?


Can I make a session object whenever I need with different configurations or is there any constraint on creating session objects?


Solution

  • There are no constraints on creating session objects. In fact, the documentation clearly encourages creating additional sessions for handling requests with the same session configuration:

    With the NSURLSession API, your app creates one or more sessions, each of which coordinates a group of related data transfer tasks. For example, if you are writing a web browser, your app might create one session per tab or window, or one session for interactive use and another session for background downloads.

    This, of course, does not imply that you should create a separate session for each and every request you make.