Skip to content

Instantly share code, notes, and snippets.

@aceontech
Created February 25, 2014 15:05
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 aceontech/9210585 to your computer and use it in GitHub Desktop.
Save aceontech/9210585 to your computer and use it in GitHub Desktop.
Utility category for deleting all cookies from a given domain.
//
// Created by Alex Manarpies on 25/02/14.
//
@interface NSHTTPCookieStorage (Util)
/**
* Iterates over all cookies for a given a domain and deletes them from the cookie store.
*/
- (void)util_deleteCookiesForURL:(NSURL*)url;
@end
//
// Created by Alex Manarpies on 25/02/14.
//
#import "NSHTTPCookieStorage+Util.h"
@implementation NSHTTPCookieStorage (Util)
- (void)util_deleteCookiesForURL:(NSURL *)url
{
NSArray *cookies = [self cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies) {
[self deleteCookie:cookie];
}
}
@end
@aceontech
Copy link
Author

Usage example:

[[NSHTTPCookieStorage sharedHTTPCookieStorage] util_deleteCookiesForURL:self.baseURL];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment