您的位置:首页 > 移动开发

iOS webview清除缓存

2016-07-04 18:20 302 查看
使用ios的webview会自动进行缓存,我们在开发的时候要记得清除Cookie和缓存。

在webview的关闭按钮中添加两个方法

/**webView退出方法*/
- (void)closeBtnAction:(UIButton *)button{
_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];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios cookie 缓存 webview