删除WKWebview 的缓存

 if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
 WKWebsiteDataStore *dateStore = [WKWebsiteDataStoredefaultDataStore];
[dateStore fetchDataRecordsOfTypes:[WKWebsiteDataStoreallWebsiteDataTypes]
 completionHandler:^(NSArray * __nonnull records) {
 for (WKWebsiteDataRecord *record inrecords) {
 [[WKWebsiteDataStoredefaultDataStore] removeDataOfTypes:record.dataTypes
 forDataRecords:@[record]
completionHandler:^{
DLog(@"Cookies for %@ deleted successfully",record.displayName);
 }
 }];
} else {
 NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
 NSString *cookiesFolderPath = [libraryPath stringByAppendingString:@"/Cookies"];
 NSError *errors;
 [[NSFileManager defaultManager]removeItemAtPath:cookiesFolderPath error:&errors];
  }
 NSString *libraryDir = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES)[0];
 NSString *bundleId  =  [[[NSBundle mainBundle] infoDictionary]
 objectForKey:@"CFBundleIdentifier"];
 NSString *webkitFolderInLib = [NSStringstringWithFormat:@"%@/WebKit",libraryDir];
 NSString *webKitFolderInCaches = [NSString
 stringWithFormat:@"%@/Caches/%@/WebKit",libraryDir,bundleId];
 NSError *error;
 /* iOS8.0 WKWebView Cache的存放路径 */
 [[NSFileManager defaultManager] removeItemAtPath:webKitFolderInCaches error:&error];
  [[NSFileManager defaultManager] removeItemAtPath:webkitFolderInLib error:nil];
 /* iOS7.0 UIWebView Cache的存放路径 */
 [[NSFileManager defaultManager] removeItemAtPath:webKitFolderInCachesfs error:&error];
}

你可能感兴趣的:(删除WKWebview 的缓存)