This can be useful for setting an array of cookies in NSHTTPCookieStorage. I ran into this problem and I decided to use the code below. Hope this will be useful for anyone trying to set an array of cookies.
NSDictionary *cookieProperties = [NSDictionary dictionaryWithObjectsAndKeys: @".domain.com", NSHTTPCookieDomain, @"/", NSHTTPCookiePath, @"SESSION", NSHTTPCookieName, @"Session value",NSHTTPCookieValue,nil]; NSDictionary *cookieProperties1 = [NSDictionary dictionaryWithObjectsAndKeys: @".domain.com", NSHTTPCookieDomain, @"/", NSHTTPCookiePath, @"some cookie", NSHTTPCookieName, @"some cookie value",NSHTTPCookieValue,nil]; NSHTTPCookie *cookie1 = [NSHTTPCookie cookieWithProperties:cookieProperties1]; NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties]; NSArray* cookieArray = [NSArray arrayWithObjects: cookie,cookie1, nil]; [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookieArray forURL:[NSURL URLWithString:urlString] mainDocumentURL:nil];
You can cross-check your cookies using the code below.
[[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSLog(@"Printing cookies %@", obj); }];
source share