在WKWebView中禁用Cookie [英] Disabling cookies in WKWebView
本文介绍了在WKWebView中禁用Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否完全可以在WKWebView中禁用cookie和本地存储?
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)
}
}
推荐答案
禁用cookie:
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "http://bla.com")
var myRequest = URLRequest(url: myURL!)
myRequest.httpShouldHandleCookies = false
webView.load(myRequest)
}
这篇关于在WKWebView中禁用Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文