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];
}
在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];
}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 页面缓存:内存和文件之间的那些事
- cookie的secure属性详解
- 浏览器 cookie 限制
- 浅析SQL Server中的执行计划缓存(上)
- Enterprise Library for .NET Framework 2.0缓存使用实例
- PowerShell中编程清空IE缓存方法
- PowerShell中使用.NET将程序集加入全局程序集缓存
- C#中缓存的基本用法总结
- android读写cookie的方法示例
- Android实现图片异步加载并缓存到本地
- wap开发中如何有效的利用缓存减少消息的传送量
- 浅谈COOKIE和SESSION区别