NSHTTPCookieStorage shared across multiple apps

727 views Asked by At

How do I share a NSHTTPCookieStorage across multiple iOS apps? I want MYAPP A and MYAPP B to use the same cookies, so I can switch between them easily.

I found the following method in NSHTTPCookieStorage.h but did not see it mentioned in the documentation.

+ (NSHTTPCookieStorage *)sharedCookieStorageForGroupContainerIdentifier:(NSString *)identifier NS_AVAILABLE(10_11, 9_0);
1

There are 1 answers

0
72A12F4E On

Answering my own question for the 6 other people who might run across this in the future...

In my research, I have found that sharedCookieStorageForGroupContainerIdentifier: is new functionality designed to work exclusively with NSURLSession, and allows you to directly specify cookie stores other than sharedHTTPCookieStorage.

Unfortunately, this functionality is not backwards compatible with the NSURLConnection suite of functionality, as NSURLConnection automatically persists its cookies to sharedHTTPCookieStorage, and this behavior cannot be overridden.

TL;DR: If you want your own Cookie storage use NSURLSession.