0

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.

4

2 回答 2

1

您没有将属性传递给 cookie。你要:

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

此外,使用NSDate对象而不是NSString.

于 2016-05-31T16:47:56.317 回答
0

NSHTTPCookieExpires 期望 NSDate 作为值类型,基于Apple 的文档 所以你必须使用 NSDate 类型值,例如[NSDate dateWithTimeIntervalSinceNow:60*60]设置 NSHTTPCookieExpires 键

于 2016-05-31T20:57:06.967 回答