iOS webview 清除缓存

使用iOS的UIWebview会自动进行缓存,我们在开发的时候要记得清除Cookie和缓存。

_webView = nil;

[self cleanCacheAndCookie];

调用的方法代码如下:

/**清除缓存和cookie*/

- (void)cleanCacheAndCookie{

//清除cookies

NSHTTPCookie *cookie;

NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

for (cookie in [storage cookies]){

[storage deleteCookie:cookie];

}

//清除UIWebView的缓存

NSURLCache * cache = [NSURLCache sharedURLCache];

[cache removeAllCachedResponses];

[cache setDiskCapacity:0];

[cache setMemoryCapacity:0];

}

原文地址:https://www.cnblogs.com/linusflow/p/8541899.html

时间: 2024-10-15 01:44:58

iOS webview 清除缓存的相关文章

ios webview清除缓存

UIWebView清除Cookie: //清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [storage cookies]) { [storage deleteCookie:cookie]; } UIWebView清除缓存: //清除UIWebView的缓存 [[NSURLCacheshared

iOS开发—清除缓存

iOS开发—清除缓存 一.修改了系统的头文件 报错示例: fatal error: file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h' has been modified si

iOS之清除缓存,ios缓存

//清除缓存按钮的点击事件 - (void)putBufferBtnClicked:(UIButton *)btn{ CGFloat size = [self folderSizeAtPath:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject] + [self folderSizeAtPath:NSSearchPathForDirectoriesInDomains(

处理ios webview 更新缓存本地css、js后webview缓存无法更新的问题

项目中需要使用app本地css.js,并且可以根据服务下发自动更新本地css.js.测试发现只要更新后的css或者js和更新前路径一致,webview加载的还是更新前的css.js.怀疑是webview本身缓存了css.js. 使用很多原生方法比如: [[NSURLCache sharedURLCache] removeAllCachedResponses];[[NSURLCache sharedURLCache] setDiskCapacity:0];[[NSURLCache sharedUR

iOS之清除缓存

//清除缓存按钮的点击事件 - (void)putBufferBtnClicked:(UIButton *)btn{ CGFloat size = [self folderSizeAtPath:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject] + [self folderSizeAtPath:NSSearchPathForDirectoriesInDomains(

iOS UIWebView清除缓存

UIWebView清除Cookie: //清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [storage cookies]) { [storage deleteCookie:cookie]; } UIWebView清除缓存: //清除UIWebView的缓存 [[NSURLCache share

webview清除缓存

把这几行代码进来就行了,具体效果能不能达到需求你也不知道,没法测. [[NSURLCache sharedURLCache] removeAllCachedResponses]; for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; } 有

(转)webView清除缓存

NSURLCache * cache = [NSURLCache sharedURLCache]; [cache removeAllCachedResponses]; [cache setDiskCapacity:0]; [cache setMemoryCapacity:0];

ios 中清除webView的缓存

在UIWebView下,可以使用 [[NSURLCache sharedURLCache] removeAllCachedResponses];//清除缓存 来实现清除缓存,但当替换使用WKWebView后,这个方法并不生效了(据说WKWebView不支持,我没找到官方说法-) 不过寻找了一下解决方法,分享一下 --------------IOS9以上---------------- WKWebsiteDataStore *dateStore = [WKWebsiteDataStore defa