Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding iOS Cookie Accept Policy

Tags:

ios

cookies

The Apple docs about the cookie accept policy for NSHTTPCookieStorage are confusing.

This is what the docs say:

NSHTTPCookieStorage implements a singleton object (shared instance) that manages storage of cookies. Each cookie is represented by an instance of the NSHTTPCookie class. As a rule, cookies are shared among all applications and are kept in sync across process boundaries. Session cookies (where the cookie object’s isSessionOnly method returns YES) are local to a single process and are not shared.

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

Note: Changes made to the cookie accept policy affect all currently running applications using the cookie storage.

And the following about - (void)setCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)aPolicy

The default cookie accept policy is NSHTTPCookieAcceptPolicyAlways. Changing the cookie policy affects all currently running applications using the cookie storage.

Now my first thought was if an app was to call setCookieAcceptPolicy, the change would affect other running applications. This does not appear to be the case. Calling setCookieAcceptPolicy will only affect the app which called it.

The only cookie policy which applies to all running applications is the Safari one. In iOS 7 before an app calls setCookieAcceptPolicy, it uses the safari policy. So if the safari cookie policy is set to always block, then any app won't be able to use cookies until it sets its own cookie policy. I understand this has caused issues for a lot of apps since iOS 7 came out.

Is my observation correct about all this, or have I missed something?

Edit

I've raised a bug with Apple and waiting to hear back from them now.

like image 896
RohinNZ Avatar asked Sep 23 '13 00:09

RohinNZ


People also ask

Is it OK to accept cookies on iPhone?

And some privacy advocates recommend blocking cookies entirely, so that websites can't glean personal information about you. That said, while occasionally clearing cookies can be beneficial, we recommend leaving your cookies enabled because blocking them leads to an inconvenient and unsatisfying web experience.

What does accept cookies mean on iPhone?

A cookie is a piece of data that a site puts on your device, so that site can remember you when you visit again. To choose whether Safari blocks cookies, tap Settings > Safari, then turn on Block All Cookies. If you block cookies, some web pages might not work.

What is Httpcookiestorage?

A container that manages the storage of cookies.


1 Answers

I've run some tests on my app and found that on iOS 7, the default cookie policy for apps is set to Safari's cookie policy. Changing the cookie policy in Safari, killing, and then restarting my apps, also would change the cookie policy in my apps. Adding the following line to my each of my apps:

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

Would change my apps accordingly, but not have any effect on Safari. Also, changing one app did not seem to affect any other of my apps.

like image 89
user503821 Avatar answered Sep 18 '22 17:09

user503821