I have a UIWebView, and I don't want it to store an cookies, so just before the webview is loaded I do:
NSArray* cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
for (NSHTTPCookie *cookie in cookies) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
Checking the count of cookies is 0 so they are all deleted. But when I go to stackoverflow it still recognizes my Google Account and logs me in. How does this happen? I though it worked with cookies?
The code above has no effect with the new web view since each WKWebView instance has its own cookie storage represented by WKHTTPCookieStore class.
Apple is phasing out UIWebView, which is used by developers for integrating web content into an app in a quick and secure manner. Apple is replacing UIWebView (and WebView) with WKWebView, an updated version, as UIWebView has been deprecated.
Cookie from WebView to another WebViewAs long as they are in the same domain, hence the cookies are shared across them.
Unlike UIWebView, which does not support server authentication challenges, WKWebView does. In practical terms, this means that when using WKWebView, you can enter site credentials for password-protected websites.
I had to deal with the exact same issue and I found 2 ways to deal with that problem. I first noticed that cookies get (sometimes) set at weird times (Strange behaviour especially with ios 4.0).
I then integrated a persistant, manual flag that was set True on a "logout" (aka clear all cookies / delete other user data) action. upon the next login (aka user-login-based action) I cleared the cookies again (the same way you did it in your code-post).
Later I found out, that listening to NSHTTPCookieManagerCookiesChangedNotification
and then deleting cookies worked really well too.
hope I could help.
Try changing the cookie acceptance policy instead:
[NSHTTPCookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With