清除缓存

清除所有的cookie 方法:

NSURL *url= [NSURL URLWithString:@"http://www.baidu.com"];

if (url) {

NSArray *cookies= [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];

for (inti=0; i<[cookies count]; i++) {

NSHTTPCookie *cookie= (NSHTTPCookie *)[cookies objectAtIndex:i];

[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];

}

清除某一个特定的cookie方法:

NSArray *cookArray= [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:self.loadURL]]; NSString *successCode= @""; for (NSHTTPCookie*cookie in cookArray) { if ([cookie.name isEqualToString:@"cookiename"]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; } }

清除某一个url缓存的方法

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:[NSURLRequest requestWithURL:url]];

你可能感兴趣的:(清除缓存)