Skip to content

Instantly share code, notes, and snippets.

@DaveWoodCom
Created September 19, 2012 09:44
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 DaveWoodCom/3748745 to your computer and use it in GitHub Desktop.
Save DaveWoodCom/3748745 to your computer and use it in GitHub Desktop.
Objective-C - clearCookies functions
// By Dave Wood - Released into the Public Domain
+ (void)clearCookies
{
NSHTTPCookieStorage *httpCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *httpCookie in [httpCookieStorage cookies])
{
[httpCookieStorage deleteCookie:httpCookie];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
// domain passed should be something like @".app.net", the leading dot prevents deleting somethingelseapp.net
+ (void)clearCookiesForDomain:(NSString *)domain
{
NSHTTPCookieStorage *httpCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *httpCookie in [httpCookieStorage cookies])
{
if ([httpCookie.domain hasSuffix:domain])
{
[httpCookieStorage deleteCookie:httpCookie];
}
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment