Reputation: 51
In my iPhone application I want to clear the cache and cookies at the logout page. Please give proper suggestions for that. Now I am using the below code, but it is not working properly.
[[NSURLCache sharedURLCache] removeAllCachedResponses];
Upvotes: 2
Views: 2412
Reputation: 3364
I've been able to make it work using NSHTTPCookie
and NSHTTPCookieStorage
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:@"facebook"]; //i used this to remove facebook related cookie so gave the domain name as facebook
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
I've never actually worked with clearing cache, but used a piece of code which disables caching
NSURLCache *disableCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:disableCache];
[disableCache release];
Upvotes: 5