Install NSHTTPCookieExpires Manually

I want to install NSHTTPCookiein NSHTTPCookieStorage.

To do this, I create a cookie and add it to NSHTTPCookieStorage, as shown below: -

NSDictionary  *propertiesDevice = [NSDictionary dictionaryWithObjectsAndKeys:
                                   @"http://www.sample.com/", NSHTTPCookieDomain,
                                   @"/", NSHTTPCookiePath,
                                   @"someCookieName", NSHTTPCookieName,
                                   @"myCookieValue", NSHTTPCookieValue,
                                   timeStamp,NSHTTPCookieExpires,nil];
NSHTTPCookie *cookieDevice = [NSHTTPCookie cookieWithProperties:propertiesDevice];
[[NSHTTPCookieStorage sharedHTTPCookieStorage]setCookie:cookieDevice];

All properties NSHTTPCookieare set as expected except NSHTTPCookieExpires.

  • If I pass [NSDate date], the value will be set. But the problem is not in the desired format NSHTTPCookie Expires=Tue, 15-Jan-2013 21:47:38 GMT. Format [NSDate date]- 2014-06-19 12:04:00 +0000.
  • When I try to change the format NSDateusing NSDateFormatter, output NSString.
  • The problem is that no matter what NSStringI install on the key NSHTTPCookieExpires, it takes on a value null.

Although the documentation says it NSHTTPCookieExpiresaccepts NSStringor NSDate.

    From Apple Doc:-

    <td>NSHTTPCookieExpires</td>
    <td>NSDate or NSString</td>
    <td>NO</td>
    <td>Expiration date for the cookie. Used only for version 0
    cookies. Ignored for version 1 or greater.</td>

- , NSString NSHTTPCookieExpires?

+4

Source: https://habr.com/ru/post/1545225/


All Articles