使用 WKWebView 在 iOS 中进行隐私浏览
根据苹果文档:
要支持隐私浏览,请在创建 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)