iOS 11 brings some updates for WKWebView including cookies managment. I've started migrating my app from UIWebView and ran into a problem: even though WKHttpCookieStore provides a method for deleting cookies (deleteCookie:completionHandler:, Xamarin wrapper: DeleteCookieAsync), in fact it doesn't delete all cookies. Here is my code:
WKHttpCookieStore cookieStore = WKWebsiteDataStore.DefaultDataStore.HttpCookieStore;
// Delete all cookies
NSHttpCookie[] allCookies = await cookieStore.GetAllCookiesAsync();
foreach (NSHttpCookie cookieToDelete in allCookies)
{
await cookieStore.DeleteCookieAsync(cookieToDelete);
}
NSHttpCookie[] newCookies = await cookieStore.GetAllCookiesAsync();
// why newCookies is not an empty array?
myWkWebView.LoadRequest(new NSUrlRequest(new NSUrl("https://facebook.com/")));
For example, this cookie is being deleted:
NSHTTPCookie
version:1
name:c_user
value:100015842...
expiresDate:'2017-12-27 07:37:39 +0000'
created:'2017-09-28 07:39:01 +0000'
sessionOnly:FALSE
domain:.facebook.com
partition:none
path:/
isSecure:TRUE
path:"/"
isSecure:TRUE
But this one isn't:
NSHTTPCookie
version:1
name:sb
value:bKbMW......OJ1V
expiresDate:'2019-09-28 07:37:39 +0000'
created:'2017-09-28 07:39:15 +0000'
sessionOnly:FALSE
domain:.facebook.com
partition:none
path:/
isSecure:TRUE
path:"/"
isSecure:TRUE
Same problem with native Swift app. I'm quite confused since similar code works just fine with NSHttpCookieStorage + UIWebView.
Is this expected behavior? If so, why? Is there a way to clean cookies in WKHttpCookieStore?