Disabling cookies in WKWebView

萝らか妹 提交于 2021-01-24 07:27:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!