我必须设置 NSHTTPCookie 使其到期设置为Session。我使用以下代码来设置该 cookie 的属性。
NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
[cookieProperties setObject:@"mycookiename" forKey:NSHTTPCookieName];
[cookieProperties setObject:@"mycookievalue" forKey:NSHTTPCookieValue];
[cookieProperties setObject:[NSNumber numberWithBool:TRUE] forKey:NSHTTPCookieSecure];
[cookieProperties setObject:@"com.mydomain" forKey:NSHTTPCookieDomain];
[cookieProperties setObject:@"com.mydomain" forKey:NSHTTPCookieOriginURL];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
但是,上述两个属性都将到期时间设置为2001 年 1 月 1 日 02:00:00 GMT+2,而不是将到期时间设置为Session