我有一个 UIWebView,我不希望它存储 cookie,所以在加载 webview 之前我会这样做:
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];
}
检查 cookie 的计数为 0,因此它们都被删除.但是当我去 stackoverflow 时,它仍然可以识别我的 Google 帐户并让我登录.这是怎么发生的?我认为它与 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?
我不得不处理完全相同的问题,我找到了两种方法来处理这个问题.我首先注意到 cookie 会(有时)在奇怪的时间设置(奇怪的行为,尤其是 ios 4.0).
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).
然后我集成了一个持久的手动标志,该标志在注销"(也就是清除所有 cookie/删除其他用户数据)操作时设置为 True.在下一次登录(也就是基于用户登录的操作)时,我再次清除了 cookie(与您在代码发布中所做的相同).
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).
后来我发现,听 NSHTTPCookieManagerCookiesChangedNotification
然后删除 cookie 也很有效.
Later I found out, that listening to NSHTTPCookieManagerCookiesChangedNotification
and then deleting cookies worked really well too.
希望我能帮上忙.
这篇关于UIWebView 中的 Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!