Skip to content

Instantly share code, notes, and snippets.

@samsymons
Created November 14, 2013 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsymons/7476614 to your computer and use it in GitHub Desktop.
Save samsymons/7476614 to your computer and use it in GitHub Desktop.
NSDictionary *properties = @{NSHTTPCookieName: @"cookie_name", NSHTTPCookieDomain: @"example.com", NSHTTPCookiePath: @"/", NSHTTPCookieValue: @"12345"};
NSHTTPCookie *sessionCookie = [NSHTTPCookie cookieWithProperties:properties];
// Set up a custom cookie storage object:
NSHTTPCookieStorage *customStorage = [[NSHTTPCookieStorage alloc] init];
[customStorage setCookie:sessionCookie];
NSLog(@"Custom cookies: %@", customStorage.cookies); // Returns nil
// Use the shared cookie storage:
NSHTTPCookieStorage *sharedStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[sharedStorage setCookie:sessionCookie];
NSLog(@"Shared cookies: %@", sharedStorage.cookies); // Returns an array containing the cookie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment