WKWebView get cookies
<h1>Aim:</h1>

<p>I would like to get all the cookies from <code>WKWebView</code> after being redirected to a specific URL.</p>

<h1>Problem:</h1>

<p>I am not able to get all the cookies, some cookies are missing.</p>

<h1>Options tried so far without much success:</h1>

<h2>1. Observe notification</h2>

<pre><code>private func addObserver() {

    NSNotificationCenter.defaultCenter().addObserver(self,
                                                     selector: #selector(didChangeCookiesWithNotification(_:)),
                                                     name: NSHTTPCookieManagerCookiesChangedNotification,
                                                     object: nil)


}

@objc private func didChangeCookiesWithNotification(notification: NSNotification?) {

    print("cookies changed")
    print("Finish cookies location = \(NSHTTPCookieStorage.sharedHTTPCookieStorage())")
    print("Finish cookies count    = \(NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies?.count)")
    print("Finish cookies          = \(NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies?.map { "\($0.name) --- Domain = \($0.properties?["Domain"])" } )")
}
</code></pre>

<h2>2. Redirect</h2>

<pre><code>func webView(webView: WKWebView,
             didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {


    print("redirected URL = \(webView.URL)")


    print("Redirect cookies location = \(NSHTTPCookieStorage.sharedHTTPCookieStorage())")
    print("Redirect cookies count    = \(NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies?.count)")
    print("Redirect cookies          = \(NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies?.map { "\($0.name) --- Domain = \($0.properties?["Domain"])" } )")
}
</code></pre>

<h2>3. Reset process pool</h2>

<pre><code>//Inside didReceiveServerRedirectForProvisionalNavigation
webView.configuration.processPool = WKProcessPool()
</code></pre>

<h1>Questions:</h1>

<ol>
<li>How do I get all the cookies after a redirect to a specific URL ? </li>
<li>Is there a different location on to which where the cookies get written
in real time ? </li>
<li>How do I force the cookies to be written ? </li>
<li>How can I be notified when a cookie gets added ? </li>
<li>Do I need to adopt a different approach ?</li>
</ol>