I'm trying to share WKWebView Cookies with UIWebView for getting all cookies. I know its very simple to get all cookies from UIWebView as compare WKWebView.
I create two WebView's (WKWebView, UIWebView) in Tabbed Application Template. Below method that i am using for share WKWebView cookies with UIWebView but didn't get success.
func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
let response = navigationResponse.response as? HTTPURLResponse
let cookies = HTTPCookie.cookies(withResponseHeaderFields: response?.allHeaderFields as! [String : String], for: (response?.url)!)
HTTPCookieStorage.shared.cookieAcceptPolicy = HTTPCookie.AcceptPolicy.always
for cookie in cookies {
HTTPCookieStorage.shared.setCookie(cookie)
}
decisionHandler(WKNavigationResponsePolicy.allow);
}
Using above code when i Login Into my account from WKWebView, UiWebView didn't Login me already. I also tried to share UIWebView Cookies With WKWebView, and it worked.
Please can anyone tell me how i can share WKWebView Cookies With UIWebView or how i can get all cookies from WKWebView?
Thanks
You need to set the wkwebview cookies by following the steps below
first in the initialization is to execute the script to set up Cookies:
And then manually add cookies to the header of the HTTP when creating the NSURLRequest object: