Why does NSHTTPCookieStorage not save cookies correctly?

I'm having some weird issues with NSHTTPCookieStorage in my iPhone app. When I call the login action of my web service, the service sends back a cookie called "auth", as well as some other cookies.

When I register a user, I invoke a logout action on the server that deletes cookies. If I print the result of [cookie NSHTTPCookieStorage] before calling logout, I see the cookie as expected. After logging out, I see that the auth cookie no longer exists (as expected).

However, if I close the application and reload it, the auth cookie will return!

I'm not sure what is going on here. It is one thing if NSHTTPCookieStorage simply did not save cookies, but it seems that some of them are saved.

Does anyone know what is going on? Do I need to manage files manually? Is there a way to commit what is in NSHTTPCookieStorage to disk?

+4
source share
3 answers

There are three URL-related local storage engines that affect how authentication processes are handled: (obviously) NSHTTPCookieStorage , NSURLCredentialStorage and NSURLCache . NSURLCredentialStorage is probably the next place you should look at, but clearing all caches is usually considered the most reliable way to achieve the desired effect.

This snippet is convenient: https://gist.github.com/559071 (clears all caches).

+1
source

Nick, I assume you are building an iOS 4.x SDK with Xcode 3.x. It may be a long shot, but you mentioned that you close the application and then start it again. Starting with iOS 4.x, multitasking is enabled by default in iPhone apps. This means whether you want it or not, your application will remain in memory if you just close it as usual. To defeat this, go to your application-name-Info.plist and add the key "Application does not work in the background" to the list. Then check the box. I would recommend you do a full cleanup and build at this point after saving your project. In addition, I would recommend, if you use in the simulator, that you completely reset the simulator by selecting “iPhone Simulator” and then “Reset Content and Settings” in the application’s drop-down menu.

0
source

I also ran into the same problem and solved it using NSUserDefaults.

Refer to this link .

0
source

All Articles