WKWebView|WKWebView 的清理缓存
oc:
// 清理clearWKWebViewCache缓存
- (void)clearCache {
if ([[[UIDevice currentDevice]systemVersion]intValue ] >= 9.0) {
NSArray * types =@[WKWebsiteDataTypeMemoryCache,WKWebsiteDataTypeDiskCache];
// 9.0之后才有的
NSSet *websiteDataTypes = [NSSet setWithArray:types];
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
}];
}else{
NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES) objectAtIndex:0];
NSString *cookiesFolderPath = [libraryPath stringByAppendingString:@"/Cookies"];
NSLog(@"%@", cookiesFolderPath);
NSError *errors;
[[NSFileManager defaultManager] removeItemAtPath:cookiesFolderPath error:&errors];
}
}
swift:
// MARK: - 清空缓存
func ClearCache() {
let dateFrom: NSDate = NSDate.init(timeIntervalSince1970: 0)
if #available(iOS 9.0, *) {
let websiteDataTypes: NSSet = WKWebsiteDataStore.allWebsiteDataTypes()
WKWebsiteDataStore.defaultDataStore().removeDataOfTypes(websiteDataTypes as! Set, modifiedSince: dateFrom) {
print("清空缓存完成")
}
} else {
let libraryPath = NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true)[0]
let cookiesFolderPath = libraryPath.stringByAppendingString("/Cookies")
let errors: NSError
try? NSFileManager.defaultManager().removeItemAtPath(cookiesFolderPath)
}
}
推荐阅读
- 热闹中的孤独
- JAVA(抽象类与接口的区别&重载与重写&内存泄漏)
- 放屁有这三个特征的,请注意啦!这说明你的身体毒素太多
- 一个人的旅行,三亚
- 布丽吉特,人生绝对的赢家
- 慢慢的美丽
- 尽力
- 一个小故事,我的思考。
- 家乡的那条小河
- 《真与假的困惑》???|《真与假的困惑》??? ——致良知是一种伟大的力量