UIWebView中的Cookie [英] Cookies in UIWebView

查看:64
本文介绍了UIWebView中的Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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帐户和登录我。这是怎么回事?

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆