Since its introduction, I've been using WKWebView's instead of UIWebView's. I've been using the delegate method webView(decidePolicyFor navigationResponse) function to access the navigationResponse object, and its response property's allHeaderFields property in order to read the cookies from any given request.
public func webView(webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
guard let response = navigationResponse.response as? HTTPURLResponse,
let url = response.url,
response.statusCode == 200,
let headers = response.allHeaderFields as? [String: String] else {
decisionHandler(.cancel)
return
}
let cookies: NSArray = HTTPCookie.cookies(withResponseHeaderFields: headers, for: url) as NSArray
for cookie in cookies {
let aCookie = cookie as! HTTPCookie
print("Background oAuth wkwebview response cookie: \(aCookie.name)")
HTTPCookieStorage.shared.setCookie(aCookie)
}
decisionHandler(.allow)
}
In iOS 9-12(inc. beta 1-12&GM) up until last week, 'cookies' in the above code was always populated if the response had cookies in the headers. As of this week, with the release of iOS 12, cookies is always empty on iOS 12. I have a number of devices I've tested this on, but for any device running any version of iOS 12, the cookies are inaccessible. All prior device firmware versions still work as expected.
I have one device that has been on 12 Beta 1 firmware since its release. This code was functional on this device up until this week. Why would the cookies suddenly stop being accessible on iOS 12, without a firmware update?