【问题标题】:how to support incognito/private mode in wkwebview/uiwebview如何在 wkwebview/uiwebview 中支持隐身/私人模式
【发布时间】:2017-08-24 21:48:32
【问题描述】:

我正在使用隐身浏览器。当我清除所有 cookie 时,我正在使用 wkwebview 我可以看到像 google 这样的流行搜索引擎会记住已经进行的搜索。

我尝试使用 NSURLSession 清除 NSHTTPCookieStorage 和 resetcookies 中的所有 cookie,但仍然无法正常工作。

【问题讨论】:

    标签: ios caching nsurlsession wkwebview nshttpcookie


    【解决方案1】:

    设置nonpersistentdatastorewkwebsitedatastorewkwebviewconfigurationwkwebview

    uiwebview 中为NSURlrequest 设置NSURLrequestreloadcacheignoringlocalandremotecachedata

    参考

    Creating a non-tracking in-app web browser

    【讨论】:

    • 正是我想要的!
    • 我们现在必须使用 WKWebsiteDataStore.nonPersistent() 来创建一个非持久性数据存储,然后在使用上述配置实例化 WKWebView 之前将其分配给 configuration.websiteDataStore。
    【解决方案2】:

    在 iOS 中使用 WKWebView 进行私密浏览

    根据苹果文档要支持隐私浏览,请在创建 Web 视图之前创建一个数据存储对象并将其分配给 WKWebViewConfiguration 对象的 websiteDataStore 属性。 default() 方法返回将网站数据持久保存到磁盘的默认数据存储。要实现隐私浏览,请改用 nonPersistent() 方法创建一个非持久性数据存储。

        let webConfiguration = WKWebViewConfiguration()
        webConfiguration.processPool = WKProcessPool()
        webConfiguration.websiteDataStore = WKWebsiteDataStore.nonPersistent()
        let webView = WKWebView(frame: self.webContainerView.bounds, configuration: webConfiguration)
        // Set up request
        if let requestURL = URL(string: "enter_url_to_load") {
            var request = URLRequest(url: requestURL)
            request.httpShouldHandleCookies = false
            request.cachePolicy = .reloadIgnoringLocalAndRemoteCacheData
            webView.navigationDelegate = self
            webView.load(request)
        }
        self.webContainerView.addSubview(webView)
    

    【讨论】:

      猜你喜欢
      • 2015-02-22
      • 2021-03-28
      • 1970-01-01
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多