I have this WKWebView which loads a login page and what I need is the "iPlanetDirectoryPro" cookie (see picture bellow) that is set after a successful login (form submit). So, I'm trying to store it in order to use it in another WKWebView.. The funny thing is "sharedHTTPCookieStorage" contains the other cookies but not the "iPlanetDirectoryPro" one.
What I tried so far:
- Created a shared proccess pool and used the same configuration for this first WKWebView and the one I'm trying to use "iPlanetDirectoryPro" on.
I used this delegate method decidePolicyForNavigationResponse to fetch cookies:
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{ NSHTTPURLResponse *response = (NSHTTPURLResponse *)navigationResponse.response; NSArray *cookies =[NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:response.URL]; for (NSHTTPCookie *cookie in cookies) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie]; } decisionHandler(WKNavigationResponsePolicyAllow); }
Evaluating JavaScript command document.cookie on webView.
Any ideas?