how to support incognito/private mode in wkwebview/uiwebview
Asked Answered
E

2

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.

Eats answered 30/3, 2017 at 19:31 Comment(0)
M
12

Set nonpersistentdatastore for wkwebsitedatastore for wkwebviewconfiguration for wkwebview

Set NSURLrequestreloadcacheignoringlocalandremotecachedata for NSURlrequest in uiwebview

Reference

Creating a non-tracking in-app web browser

Montanez answered 30/3, 2017 at 20:27 Comment(2)
Exactly what I was looking for!Potent
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.Marvelmarvella
D
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)
Danelledanete answered 15/7, 2021 at 6:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.