3

I've been thumbing through the Apple documentation and I can't seem to find out if cookies are saved/used for every instance of NSURLConnection, or just a single instance. It seems as though the cookies are hanging around even after I release my individual instances of NSURLConnection, but I am unsure if my tests are comprehensive. Any help on this would be greatly appreciated.

Thanks in advance!

The Maniac
  • 2,628
  • 3
  • 19
  • 29
  • I don't know the answer so I'll add this as a comment, but from this SO thread: http://stackoverflow.com/questions/704985/objective-c-asynchronous-web-request-with-cookies it looks like you use NSCookieStorage to persist cookies. – D.C. Dec 03 '10 at 00:15
  • Thanks for the link Darren, very informative. Quoting the [NSHTTPCookieStorage documentation](http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSHTTPCookieStorage_Class/Reference/Reference.html), "NSHTTPCookieStorage implements a singleton object (shared instance) that manages the shared cookie storage". My guess is that the cookies do persist over NSURLConnection instances, but I'll leave my question unanswered until someone can offer proof. – The Maniac Dec 03 '10 at 01:08

1 Answers1

2

It depends on which operating system you are developing. On Mac OS X, cookies are shared by all processes for a given user. On iOS, they are not. In both cases, cookies accepted by a given application are shared within the application process and across instances of the application.

Again, from the documentation of NSHTTPCookieStorage:

NSHTTPCookieStorage implements a singleton object (shared instance) that manages the shared cookie storage. These cookies are shared among all applications and are kept in sync cross-process.

(bold emphasis mine)

Further,

iOS Note: Cookies are not shared among applications in iOS.

(bold emphasis theirs)

Ryan
  • 16,626
  • 2
  • 23
  • 20