Clear cookies for WKWebView?

后端 未结 2 1771
予麋鹿
予麋鹿 2020-12-18 01:06

For an iOS 8 app I want to use a WKWebView for a custom authentication ViewController that I\'m building. However, I can\'t seem to figure out how to clear the

2条回答
  •  不知归路
    2020-12-18 01:35

    The answer was provided to me on the internal Apple forums: use a mutable NSURLRequest, and set HTTPShouldHandleCookies to NO:

    let req: NSMutableURLRequest = NSMutableURLRequest(URL:openURL)
    req.HTTPShouldHandleCookies = false
    webView.loadRequest(req)
    

    No cookies sent to the web site, so you get the login screen (for testing) every time.

提交回复
热议问题