原来设置cookie的时候,只是设置了子域名(例如m.abc.com),后来需要跨域(整个域名有效),就将NSHTTPCookieDomain改成abc.com,测试发现并没有效果(android上直接设置abc.com是正常的);后来将NSHTTPCookieDomain的值换成.abc.com(在域名前面加多个点)就可以了。
NSDictionary * cookieInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"1"
, NSHTTPCookieValue
, @"cok_framename"
, NSHTTPCookieName
, @"/"
, NSHTTPCookiePath
, @".abc.com"
, NSHTTPCookieDomain
,NULL];
NSHTTPCookie * userCookie = [NSHTTPCookie cookieWithProperties:cookieInfo];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:userCookie];