问题
Is it possible at all to disable cookies and local storage in a WKWebView?
Let's say that this is my setup, and I want to add something that disables them:
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "http://bla.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
}
回答1:
To disable cookies:
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "http://bla.com")
var myRequest = URLRequest(url: myURL!)
myRequest.httpShouldHandleCookies = false
webView.load(myRequest)
}
来源:https://stackoverflow.com/questions/47559340/disabling-cookies-in-wkwebview