I am creating an iPhone app, and am using this method to create a cookie that will be accessed site-wide:
NSMutableDictionary *cookieDictionary = [NSMutableDictionary dictionaryWithCapacity:4];
[cookieDictionary setObject:@"status" forKey:NSHTTPCookieName];
[cookieDictionary setObject:[self.usernameField text] forKey:NSHTTPCookieValue];
[cookieDictionary setObject:@"http://www.mydomain.com" forKey:NSHTTPCookieDomain];
[cookieDictionary setObject:@"/" forKey:NSHTTPCookiePath];
// Build the cookie.
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieDictionary];
// Store the cookie.
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
// Log the Cookie and display it
for (cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
NSLog(@"%@", cookie.value);
}
Now I am trying to delete it via the following method, but it isn't working, and the documentation isn't quite helping me:
NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* theCookies = [cookieStorage cookiesForURL:[NSURL URLWithString:@"http://mydomain.com"]];
for (NSHTTPCookie *cookie in theCookies) {
[cookieStorage deleteCookie:cookie];
}