美文网首页
wkwebview清除缓存

wkwebview清除缓存

作者: 陌宇凡 | 来源:发表于2018-07-17 14:00 被阅读0次

在UIWebView下,可以使用

[[NSURLCache sharedURLCache] removeAllCachedResponses];//清除缓存

当使用wkwebview时候WKWebView清除cookies的方法(iOS9以上)

WKWebsiteDataStore *dateStore = [WKWebsiteDataStore defaultDataStore];

  [dateStore fetchDataRecordsOfTypes:[WKWebsiteDataStore allWebsiteDataTypes]

           completionHandler:^(NSArray * __nonnull records) {

             for (WKWebsiteDataRecord *record in records)

             {

//               if ( [record.displayName containsString:@"baidu"]) //取消备注,可以针对某域名清除,否则是全清

//               {

                 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:record.dataTypes

                                      forDataRecords:@[record]

                                    completionHandler:^{

                                      NSLog(@"Cookies for %@ deleted successfully",record.displayName);

                                    }];

//               }

             }

           }];

iOS9一下用这种方法:

NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *cookiesFolderPath = [libraryPath stringByAppendingString:@"/Cookies"];

NSError *errors;

[[NSFileManager defaultManager] removeItemAtPath:cookiesFolderPath error:&errors];

查看cookie

NSHTTPCookie *cookie;

NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];

for (cookie in [cookieJar cookies]) {

  NSLog(@"%@", cookie);

}

相关文章

  • 清楚WKWebView缓存

    WKWebView清除缓存WKWebView,在iOS9以后提供了缓存管理类WKWebsiteDataStore,...

  • WKWebView清除缓存

    一. UIWebView清楚缓存 在使用WKWebView之前使用的是UIWebView, 清除缓存的方式两种:...

  • wkwebview清除缓存

    在UIWebView下,可以使用 [[NSURLCache sharedURLCache] removeAllCa...

  • WKWebView清除缓存

    最近用WKWebView的人貌似越来越多了,有很多人问这个怎么清除缓存,下面就是清除缓存的方法,大家一起来看看行不...

  • 清除wkwebView缓存

    #pragma mark- 清除webView缓存 - (void)clearWebViewCookies{ ...

  • WKWebView清除缓存

  • wkwebview清除缓存

    Tips: 以下方法仅针对iOS9.0以上版本可用,iOS1-iOS9.0之间版本可查询其他方法,由于版本老旧,在...

  • WkWebView 清除缓存 ios8

    WkWebView 清除缓存 ios8iOS8系统NSString *libraryDir = NSSearchP...

  • Swift Tip4

    1、iOS 开发textView不能从顶部显示: 2.WKWebView清除缓存: 3.webView设置缓存策略...

  • WKWebView如何清除缓存

    WKWebView如何清除缓存 iOS7.0只有UIWebView, 而iOS8.0是有WKWebView, 但8...

网友评论

      本文标题:wkwebview清除缓存

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