1


I am developing a WKWebview app in swift. Here One needs to login to a specific domain. For this , I am throwing a cookie with logged in information/token. But the problem occurs when I try to logout and the check if token exists? And the token still exists even after logout.

Note - I checked on chrome browser on mac, and here it works perfectly.

Shivam Tripathi
  • 1,405
  • 3
  • 19
  • 37

1 Answers1

0

WKWebView runs all of its networking in a separate process and thus does not ‘see’ your process’s cookie store.

The problem is that the WKWebView does not write back the cookies immediately. I think it does this on its own schedule. For example when a WKWebView is closed or maybe periodically.

In iOS 11 we added WKHTTPCookieStore to give you full access to the web view’s cookie store.

Supported cookie sync with WKWebView on older platforms is tricky. There are two techniques that might work:

  1. You can set a cookie in the headers of the request you pass to

    [WKWebView loadRequest:].

  2. You can get and set cookies from within the web view by running JavaScript code (using -evaluateJavaScript:completionHandler:) that accesses the JavaScript document.cookie value.

For more reference https://forums.developer.apple.com/thread/95301 additionally some workaround Getting all cookies from WKWebView

Vinaykrishnan
  • 740
  • 3
  • 14
  • 34