2

I currently have an issue with hybrid application that uses an WKWebView to display a webpage.

After the application restarts and creates a new session / WKWebWiew, a new login cookie is given to the WKWebView from the webservice. This works fine in two out of three attempts but in some cases, the login cookie is not stored in shared cookie storage used by WKWebView (NSHTTPCookieStorage).

(Using same webservice with UIWebview works fine)

I have tried network analyzing tools and I can see that the webservice is sending me the new cookie. For some reason WKWebView / NSURLRequest does not store the updated login cookie. I have read that WKWebView seems to update the cookies in scheduled intervals and that you can force it to update by updating the WKProcessPool, but with no success.

I have been trying to read the login cookie from the webservice using:

- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
...
NSHTTPURLResponse *urlResponse = (NSHTTPURLResponse *)navigationResponse.response; 
NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:urlResponse.allHeaderFields forURL:urlResponse.URL];
...

But for some reason the session cookies / login cookies are not visible in the header and my guess is that its hidden by NSURL for some reason since I can see them if I turn off the automatic Cookie handling by setting:

<NSMutableURLRequest>.HTTPShouldHandleCookies

It does however give me a lot of other issues...

Has anyone had similar problems or any input?

oscar
  • 589
  • 1
  • 4
  • 17

0 Answers0