Created
December 29, 2020 20:03
-
-
Save noahsark769/bf9f7cfef42754b29e41f518f00611b9 to your computer and use it in GitHub Desktop.
Copying WKWebView cookies into HTTPCookieStorage
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
extension LoginViewController: WKNavigationDelegate { | |
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
if let url = webView.url, url.absoluteString.contains("/index.action") { | |
let store = WKWebsiteDataStore.default().httpCookieStore | |
store.getAllCookies { cookies in | |
if let sessionIdCookie = cookies.first(where: { cookie in | |
cookie.name == "JSESSIONID" | |
}) { | |
HTTPCookieStorage.shared.setCookies(cookies, for: webView.url, mainDocumentURL: nil) | |
self.callback(ConfluenceSessionCookie(jSessonId: sessionIdCookie)) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment