首先添加一個按鈕,點擊它的時候執(zhí)行清緩存和cookie操作,這里我重寫了導(dǎo)航的返回按鈕:
-(void)leftBarButtonClicked{
_webView = nil;
[self cleanCacheAndCookie];
[self.navigationController popViewControllerAnimated:YES];
}
/**清除緩存和cookie*/
- (void)cleanCacheAndCookie{
//清除cookies
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]){
[storage deleteCookie:cookie];
}
//清除UIWebView的緩存
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSURLCache * cache = [NSURLCache sharedURLCache];
[cache removeAllCachedResponses];
[cache setDiskCapacity:0];
[cache setMemoryCapacity:0];
}