Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSHTTPCookieStorage and Cookie Expiration Date

In our iPhone app we use two cookies during server communication. One is a short session cookie (JSESSION), and the other is a long session cookie (REMEMBER ME). If an answer comes from the server, it sends a short session cookie, which I can find in the NSHTTPCookieStorage.

My question is how this storage handles the cookie's expiration date? So if the cookie expires, does it delete that cookie automatically, and if I try to get this cookie by its name from the storage after expiration, do I get anything? Or do I have to check the expiration manually?

like image 251
madik Avatar asked Aug 26 '11 10:08

madik


People also ask

Can I subclass the nshttpcookiestorage class?

In cases where a cookie storage is shared between processes, changes made to the cookie accept policy affect all currently running apps using the cookie storage. The NSHTTPCookieStorage class is usable as-is, but you can subclass it.

What is sharedhttpcookiestorage?

A container that manages the storage of cookies. Each stored cookie is represented by an instance of the NSHTTPCookie class. The persistent cookie storage returned by sharedHTTPCookieStorage may be available to app extensions or other apps, subject to the following guidelines:

What is the persistent cookie storage for shared cookies?

Each stored cookie is represented by an instance of the HTTPCookie class. The persistent cookie storage returned by shared may be available to app extensions or other apps, subject to the following guidelines:

What is the difference between wkhttpcookiestore and UIWebView and wkwebview?

UIWebView — UIWebView instances within an app inherit the parent app's shared cookie storage. WKWebView — Each WKWebView instance has its own cookie storage. See the WKHTTPCookieStore class for more information. Session cookies (where the cookie object’s sessionOnly property is YES) are local to a single process and are not shared.


1 Answers

My question is how this storage handles the cookie's expiration date?

NSHTTPCookieStorage stores the NSHTTPCookie objects that has expiration date as one of its property.

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSHTTPCookie_Class/Reference/Reference.html#//apple_ref/occ/cl/NSHTTPCookie

So if the cookie expires, does it delete that cookie automatically, and if I try to get this cookie by it's name from the storage after expiration, do I get anything? Or do I have to check the expiration manually?

You should check manually for expiration and delete the cookie yourself

As it is referred in http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSHTTPCookie_Class/Reference/Reference.html#//apple_ref/occ/cl/NSHTTPCookie

The receiver’s expiration date, or nil if there is no specific expiration date such as in the case of “session-only” cookies. The expiration date is the date when the cookie should be deleted.
like image 157
prakash Avatar answered Sep 21 '22 20:09

prakash