iphone NSHTTPCookieStorage 在应用程序重新打开时可用? [英] iphone NSHTTPCookieStorage avaible on app reopen?

查看:41
本文介绍了iphone NSHTTPCookieStorage 在应用程序重新打开时可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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];

在它保存该 cookie 后,我将它带到主视图 - 我的问题是 - 如果用户关闭程序,手机重新启动等等 - cookie 是否存储在手机本地?我正在尝试在 didFinishLaunchingWithOptions 上再次访问该 cookie.我现在有以下代码..

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]);

每次 - 它在 cookie 数据上显示为空 - 关于每次用户关闭程序时是否清除 cookie 的任何想法 - 还是 bc im 在 iPhone 模拟器上进行测试?

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?

推荐答案

如果您或其他任何人仍然遇到此问题,可能是因为 cookie 设置为在会话结束时(应用程序关闭时)过期.您可以通过查看 NSHTTPCookiesessionOnly 属性来检查此行为(getter 方法是 -(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).

这篇关于iphone NSHTTPCookieStorage 在应用程序重新打开时可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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