In iOS 11, I set cookies on my WKWebView and made sure they were set by viewing them in the safari inspector. However, I do not think that they are transmitted at my request. Is there anything else I need to do besides setting them in webView.configuration.websiteDataStore.httpCookieStore
to get them to send a request?
I will add my naive code here, any suggestions will be very useful:
private func setCookies(for request: URLRequest) {
guard let storedCookies = HTTPCookieStorage.shared.cookies(for: request.url!) else { return }
if #available(iOS 11.0, *) {
self.webView.configuration.websiteDataStore.httpCookieStore.getAllCookies({ (webViewCookies) in
storedCookies.forEach({ (cookie) in
if !webViewCookies.contains(cookie) {
self.webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie, completionHandler: {
if let last = storedCookies.last, last == cookie {
self.webView.load(request)
}
})
}
})
})
}
}
source
share