美文网首页
删除WKWebview 的缓存

删除WKWebview 的缓存

作者: 编程猫猫 | 来源:发表于2018-03-20 11:23 被阅读0次
     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 的缓存

          本文链接:https://www.haomeiwen.com/subject/tbvvqftx.html