zoukankan      html  css  js  c++  java
  • WKWebView清除cookie缓存

    OC写法:     swift写法再下下面。

    清除WKWebView的缓存,让H5页面一刷新就更新至最新的页面

     

    直接上代码~!~~

    要区分iOS9.0和8.0两种

    - (void)deleteWebCache {

        

        if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {

            NSSet *websiteDataTypes

            = [NSSet setWithArray:@[

                                    WKWebsiteDataTypeDiskCache,

                                    //WKWebsiteDataTypeOfflineWebApplicationCache,

                                    WKWebsiteDataTypeMemoryCache,

                                    //WKWebsiteDataTypeLocalStorage,

                                    //WKWebsiteDataTypeCookies,

                                    //WKWebsiteDataTypeSessionStorage,

                                    //WKWebsiteDataTypeIndexedDBDatabases,

                                    //WKWebsiteDataTypeWebSQLDatabases

                                    ]];

            //// All kinds of data

            //NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];

            //// Date from

            NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];

            //// Execute

            [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{

                // Done

            }];

     

        } else {

            

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

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

            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 asSet<String>, modifiedSince: dateFrom) {

                    print("清空缓存完成")

                }

            } else {

                  let libraryPath = NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true)[0]

                let cookiesFolderPath = libraryPath.stringByAppendingString("/Cookies")

                let errors: NSError

                tryNSFileManager.defaultManager().removeItemAtPath(cookiesFolderPath)

            }

        }

     

    参考:

    http://www.cnblogs.com/YangFuShun/p/5855829.html

    http://www.jianshu.com/p/186a3b236bc9

  • 相关阅读:
    鬼斧神工:求n维球的体积
    一个双曲函数的积分
    复杂的对数积分(八)
    一个有意思的对数积分的一般形式
    Logarithmic-Trigonometric积分系列(二)
    Logarithmic-Trigonometric积分系列(一)
    Some series and integrals involving the Riemann zeta function binomial coefficients and the harmonic numbers
    Euler Sums系列(六)
    Euler Sums系列(五)
    级数欣赏
  • 原文地址:https://www.cnblogs.com/Walking-Jin/p/6293111.html
Copyright © 2011-2022 走看看