Created
September 12, 2018 17:00
-
-
Save flexaddicted/d1d324843c30678340f559a34ec257b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) { | |
guard let response = navigationResponse.response as? HTTPURLResponse, | |
let url = navigationResponse.response.url else { | |
decisionHandler(.cancel) | |
return | |
} | |
if let headerFields = response.allHeaderFields as? [String: String] { | |
let cookies = HTTPCookie.cookies(withResponseHeaderFields: headerFields, for: url) | |
cookies.forEach { cookie in | |
webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie) | |
} | |
} | |
decisionHandler(.allow) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where should I add this code?