10

I am working on a incongnito browser.I am using wkwebview when I clear all the cookies I can see that popular search engine like google remembers the searches that has been made.

I tried cleaning all the cookies in NSHTTPCookieStorage and resetcookies using NSURLSession but its still not working.

Shiva
  • 545
  • 1
  • 10
  • 41

2 Answers2

12

Set nonpersistentdatastore for wkwebsitedatastore for wkwebviewconfiguration for wkwebview

Set NSURLrequestreloadcacheignoringlocalandremotecachedata for NSURlrequest in uiwebview

Reference

Creating a non-tracking in-app web browser

Community
  • 1
  • 1
Veeravel
  • 284
  • 3
  • 14
  • Exactly what I was looking for! – jegadeesh Jun 12 '19 at 05:37
  • 1
    We now have to use WKWebsiteDataStore.nonPersistent() to create a non-persistent data store, then assign it to the configuration.websiteDataStore before instantiating WKWebView with the said configuration. – ekscrypto Jun 20 '19 at 15:15
2

Private browsing in iOS using WKWebView

As per apple documentation: To support private browsing,create a data store object and assign it to the websiteDataStore property of a WKWebViewConfiguration object before you create your web view. The default() method returns the default data store that saves website data persistently to disk. To implement private browsing, create a nonpersistent data store using the nonPersistent() method instead.

    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)
Ashish Chhabra
  • 2,604
  • 1
  • 11
  • 8