iphone NSHTTPCookieStorage 在应用程序重新打开时可用吗?

发布于 2024-10-11 03:50:12 字数 952 浏览 1 评论 0原文

我正在这里开发我的应用程序 - 基本上就是这样。我有一个登录框,用户在其中登录,然后它在返回时保存 cookie 数据,如下所示:

   NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[resp allHeaderFields] forURL:[NSURL URLWithString:@"http://myurl]];   
   NSHTTPCookieStorage *sharedHTTPCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
   [sharedHTTPCookieStorage setCookies:all forURL:[NSURL URLWithString:@"http://myurl"] mainDocumentURL:nil];

在它保护 cookie 后,我将其带到主视图 - 我的问题是 - 如果用户关闭 prgoram,手机会重新启动并且等等 - cookie 本身存储在手机本地吗?我试图在 didFinishLaunchingWithOptions 上再次访问该 cookie。我现在有以下代码..

 NSHTTPCookieStorage *sharedHTTPCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *cookies = [sharedHTTPCookieStorage cookiesForURL:[NSURL URLWithString:@"http://iphone.wazgood.com"]];

 NSLog(@"count: %i", [cookies count]);

每次 - cookie 数据上都是空的 - 关于每次用户关闭程序时是否清除 cookie 有什么想法 - 或者是 bc 我在 iPhone 模拟器上测试?

I am working on my app here- and it pretty much comes to this. I have a login box where a users log's in and then it saves the cookie data on return like so:

   NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[resp allHeaderFields] forURL:[NSURL URLWithString:@"http://myurl]];   
   NSHTTPCookieStorage *sharedHTTPCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
   [sharedHTTPCookieStorage setCookies:all forURL:[NSURL URLWithString:@"http://myurl"] mainDocumentURL:nil];

After it safes that cookie i take it to the home view - My problem is - if the users closes the prgoram, the phone restarts and so forth - are the cookies stored locally on the phone its sefl? I am trying to access that cookie again on the didFinishLaunchingWithOptions. I have the following code now..

 NSHTTPCookieStorage *sharedHTTPCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *cookies = [sharedHTTPCookieStorage cookiesForURL:[NSURL URLWithString:@"http://iphone.wazgood.com"]];

 NSLog(@"count: %i", [cookies count]);

Every time - it comes up empty on the cookie data - any ideas on if the cookies are cleared every time the user clsoes the program out - or is it bc im testing on the iPhone emulator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惟欲睡 2024-10-18 03:50:12

如果您或其他人仍然遇到此问题,可能是 cookie 设置为在会话结束时(应用程序关闭时)过期。您可以通过查看 NSHTTPCookiesessionOnly 属性(获取方法为 -(BOOL)isSessionOnly)来检查此行为。

In case you or anyone else is still having this problem, it could be that the cookies are set to expire when the session ends (when the app closes). You can check for this behavior by looking at the sessionOnly property of your NSHTTPCookies (the getter method is -(BOOL)isSessionOnly).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文