NSHTTPCookies拒绝被删除 [英] NSHTTPCookies refuse to be deleted

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

问题描述

我需要一个注销按钮,我的应用程序,我有以下代码:

I need a log out button for my app, I have the below code:

        while ([[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] count] != 0) {
            for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
                [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
            }
        }

删除,它只运行一次)

如果我NSlog描述共享cookie存储在上述代码后,它输出数组是空的。但是,我终止了应用程序或只是关闭它,然后NSLog的共享cookie存储的描述应用程序启动后的第一件事情,所有的cookie仍然存在。

If I NSLog the description of shared cookie storage after the above code it outputs that the array is empty. However I terminate the app or just close it, and then NSLog the description of the shared cookie storage the first thing after the app starts, all the cookies are still there.

我已经尝试设置 Cookie 为nil在for循环,甚至尝试发送dealloc的cookie(我知道你不应该这样做,但我现在正在尝试任何东西)

I have tried setting Cookie to nil in the for loop, and even tried sending dealloc to the cookies (I know you shouldn't do that but I'm now trying anything)

推荐答案


问题似乎是cookie被缓存并且不立即保存到文件。

The problem seems to be that the cookies are cached and not saved out to a file immediately.

我制作了一个示例项目来重现这个问题 - 并发现它只会发生在应用程序接收到一个SIGKILL信号,例如当调试器从Xcode停止时。在我的实验中,未处理的异常,崩溃,exit()和abort()不会导致NSHTPPCookieStorage松散数据。

I made a sample project to reproduce this issue — and found that it would only occur when the app receives a SIGKILL signal, like when the debugger is stopped from within Xcode. In my experiments, unhandled exceptions, crashes, exit() and abort() don't cause NSHTPPCookieStorage to loose data.

由于这看起来像一个仅调试问题它只会在使用调试器时发生),我关闭了之前填写的雷达

As this looks like a debugging-only issue (it only occurs when using the debugger), I closed the radar I filled previously.

我无法测试一切:可以随意使用示例项目来查看其他崩溃来源是否会触发Cookie丢失。

I couldn't test everything though: feel free to use the sample project to see if other source of crashes could trigger a cookies loss.

这篇关于NSHTTPCookies拒绝被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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