[英]how to support incognito/private mode in wkwebview/uiwebview
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.我正在使用隐身浏览器。当我清除所有 cookie 时,我正在使用 wkwebview 我可以看到像谷歌这样的流行搜索引擎会记住已经进行的搜索。
I tried cleaning all the cookies in NSHTTPCookieStorage and resetcookies using NSURLSession but its still not working.我尝试清除 NSHTTPCookieStorage 中的所有 cookie 并使用 NSURLSession 重置cookies,但它仍然无法正常工作。
Set nonpersistentdatastore
for wkwebsitedatastore
for wkwebviewconfiguration
for wkwebview
为
wkwebsitedatastore
设置nonpersistentdatastore
for wkwebviewconfiguration
for wkwebview
Set NSURLrequestreloadcacheignoringlocalandremotecachedata
for NSURlrequest
in uiwebview
在
NSURLrequestreloadcacheignoringlocalandremotecachedata
为NSURlrequest
设置uiwebview
Reference参考
Private browsing in iOS using WKWebView使用 WKWebView 在 iOS 中进行私密浏览
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.根据苹果文档:要支持隐私浏览,请在创建 Web 视图之前创建一个数据存储对象并将其分配给 WKWebViewConfiguration 对象的 websiteDataStore 属性。 The default() method returns the default data store that saves website data persistently to disk.
default() 方法返回将网站数据持久保存到磁盘的默认数据存储。 To implement private browsing, create a nonpersistent data store using the nonPersistent() method instead.
要实现隐私浏览,请改为使用 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.