在我的iPhone应用程序中,我想在注销页面清除缓存和cookie。请给出适当的建议。现在我使用下面的代码,但它无法正常工作。
[[NSURLCache sharedURLCache] removeAllCachedResponses];
答案 0 :(得分:5)
我已经能够使用NSHTTPCookie
和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];
}
}
我从未真正使用清除缓存,但使用了一段禁用缓存的代码
NSURLCache *disableCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:disableCache];
[disableCache release];