更改NSHTTPCookie创建的时间

时间:2016-02-17 11:01:51

标签: ios

所以我手动添加了一个cookie,如:

-(void)addDomainCookie:(NSString *)domainName {
    NSURL *ourURL = [NSURL URLWithString:self.APIBaseURL];
    NSArray *ourCookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:ourURL];
    if (ourCookies.count > 0) {
        NSHTTPCookie *cookie = [ourCookies firstObject];
        NSDictionary *properties = cookie.properties;
        [properties setValue:@"domain" forKey:NSHTTPCookieName];
        [properties setValue:domainName forKey:NSHTTPCookieValue];
        NSHTTPCookie *domainCookie = [NSHTTPCookie cookieWithProperties:properties];
        NSMutableArray *mutableCookies = [ourCookies mutableCopy];
        [mutableCookies addObject:domainCookie];

        [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:[mutableCookies copy] forURL:ourURL mainDocumentURL:nil];
    }

}

但是,我发现新创建的cookie的创建时间很奇怪:

<NSHTTPCookie version:0 name:"user_id" value:"56377398454919ad5cf642857fa026ce" expiresDate:2018-12-07 10:52:28 +0000 created:2016-02-17 10:52:28 +0000 sessionOnly:FALSE domain:"my.com" path:"/" isSecure:FALSE>,
<NSHTTPCookie version:0 name:"domain" value:"mydomain" expiresDate:2018-12-07 10:52:28 +0000 created:2001-01-01 00:00:01 +0000 sessionOnly:FALSE domain:"my.com" path:"/" isSecure:FALSE>

第一个cookie已创建时间2016-02-17 10:52:28 +0000,但是当我调用[NSHTTPCookie cookieWithProperties:properties];时,它返回一个cookie,创建时间为2001-01-01 00:00:01 +0000。我错过了什么?

0 个答案:

没有答案