wkwebview删除cookes和缓存
来源:互联网 发布:cnc五轴编程招聘 编辑:程序博客网 时间:2024/05/02 14:20
试了很多方法没用,最后找到这个
{ NSSet *websiteDataTypes = [NSSet setWithArray:@[ WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeOfflineWebApplicationCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeCookies, WKWebsiteDataTypeSessionStorage, WKWebsiteDataTypeIndexedDBDatabases, WKWebsiteDataTypeWebSQLDatabases ]]; //你可以选择性的删除一些你需要删除的文件 or 也可以直接全部删除所有缓存的type //NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes]; NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0]; [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{ // code }]; // 但开发app必须要兼容所有iOS版本,可是iOS8,iOS7没有这种直接的方法,那该怎么办呢?// (iOS7.0只有UIWebView, 而iOS8.0是有WKWebView, 但8.0的WKWebView没有删除缓存方法。)// 针对与iOS7.0、iOS8.0、iOS9.0 WebView的缓存,我们找到了一个通吃的办法: NSString *libraryDir = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0]; NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]; NSString *webkitFolderInLib = [NSString stringWithFormat:@"%@/WebKit",libraryDir]; NSString *webKitFolderInCaches = [NSString stringWithFormat:@"%@/Caches/%@/WebKit",libraryDir,bundleId]; NSString *webKitFolderInCachesfs = [NSString stringWithFormat:@"%@/Caches/%@/fsCachedData",libraryDir,bundleId]; NSError *error; /* iOS8.0 WebView Cache的存放路径 */ [[NSFileManager defaultManager] removeItemAtPath:webKitFolderInCaches error:&error]; [[NSFileManager defaultManager] removeItemAtPath:webkitFolderInLib error:nil]; /* iOS7.0 WebView Cache的存放路径 */ [[NSFileManager defaultManager] removeItemAtPath:webKitFolderInCachesfs error:&error];}
0 0
- wkwebview删除cookes和缓存
- webview和H5 清除缓存和缓存文件删除。
- 数据源控件和缓存
- 查询和缓存
- 自定义调节器和缓存
- 过滤器和缓存
- 网络请求和缓存
- <html5>canvas和缓存
- Hibernate查询和缓存
- 计算机内存和缓存
- ssh注解和缓存
- Cookie、Session和缓存
- Bitmap和缓存
- windows下 定时删除tomcat日志和缓存。可以保留天数
- 缓存雪崩和缓存穿透和缓存失效
- hibernate的session和缓存
- 内存和缓存的区别!
- 自旋锁和缓存一致性
- Eclipse运行项目提示“类路径引用的项目不存在”
- 加班多年,你敢说没遇过这种破事我也是服!
- mysql错误: Cannot convert value ’0000-00-00 00:00:00′ from column 10 to TIMESTAMP
- CSS预处理器——SASS学习笔记(一)
- 4.7 Swift中swift中的switch 语句
- wkwebview删除cookes和缓存
- github项目笔记
- 2个dataGridView分别导出或将数据导出到软件目录下的TXT
- 怎样在Github上托管开源代码库
- A窗体点按钮,弹出B窗体,B窗体修改了内容后,将数据传递回来到A窗体
- html5解决大文件断点续传
- Android标准目录的路径
- js~BOM之window,location,screen+事件
- 4.8 Swift中switch语句区间和元组模式匹配