0
votes

I'm creating a cookie using NSHTTPCookie. But when I create the expiration date is getting converted to creation date. Here is my code:

NSMutableDictionary *cProperties = [NSMutableDictionary dictionary];

   [cProperties setObject:@"31 May 2016 17:04:14 GMT" forKey:NSHTTPCookieExpires];
    NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:];
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];

Per console output:

    <NSHTTPCookie version:0 name:"myCookie" 
 expiresDate:(null) created:2016-05-31 16:32:37 +0000 
sessionOnly:TRUE  path:"/" isSecure:TRUE>

Any of you knows why my expiresDate is getting switch with created date ?

I'll really appreciate your help.

2
Did you by chance find a solution?h3dkandi

2 Answers

1
votes

You aren't passing the properties to the cookie. You want:

NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cProperties];
                                                          ^^^^^^^^^^^

Also it's probably easier to set the expires date/time using an NSDate object instead of an NSString.

0
votes

NSHTTPCookieExpires is expecting NSDate as a value type, based on Apple's document So you have to use NSDate type value such as [NSDate dateWithTimeIntervalSinceNow:60*60] to set NSHTTPCookieExpires key