iphone NSHTTPCookieStorage avaible on app reopen?

南笙酒味 提交于 2020-01-25 03:20:07

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/4623811/iphone-nshttpcookiestorage-avaible-on-app-reopen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!