3

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)
    }


}
Luoruize
  • 579
  • 2
  • 7
  • 25

1 Answers1

11

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)
}
Santhosh R
  • 1,518
  • 2
  • 10
  • 14