iphone NSHTTPCookieStorage avaible on app reopen?
Asked Answered
T

1

1

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?

Tournedos answered 7/1, 2011 at 8:38 Comment(1)
My guess is you may need to cal synchronize (as in NSUserDefault) when you save cookie to make it persistent for the next use. Check the functionality in device.Endogen
L
2

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

Lightyear answered 14/2, 2011 at 18:54 Comment(1)
Nope, this happens with not session only cookies also. They are gone if app crash after cookie recieve. It seems like cookies saved when u press Home button or terminate app.Sequestrate

© 2022 - 2024 — McMap. All rights reserved.