1

Using AFNetworking, I'm able to successfully login without any problems and store a session. As soon as I stop debugging in xcode, the simulator is still open but goes to the iphone homescreen. When I go to run the app again from xcode, the login session is gone and user is nil, spent a couple hours and not sure why. My question is is stop debugging messing with the session of the logged in user? Does using setAuthorizationHeaderWithUsername have to do with anything.

  @property (retain, nonatomic) NSDictionary* user;

Login:

      [[API sharedInstance] commandWithParams:params
                               onCompletion:^(NSDictionary *json) {
                                   //handle the response

                                   NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];

                                   if ([json objectForKey:@"error"]==nil && [[res objectForKey:@"IdUser"] intValue]>0) {
                                       //success
                                       [[API sharedInstance] setUser:res];
                                   }
       }];

API:

+(API*)sharedInstance
{
   static API *sharedInstance = nil;
   static dispatch_once_t oncePredicate;
   dispatch_once(&oncePredicate, ^{
      sharedInstance = [[self alloc] initWithBaseURL:[NSURL URLWithString:kAPIHost]];
});

return sharedInstance;

}
TMan
  • 4,044
  • 18
  • 63
  • 117

1 Answers1

0

You need to serialize your cookies into files or other stores.

See this answer:

Community
  • 1
  • 1
ZhangChn
  • 3,154
  • 21
  • 41
  • Thx for response, any way you can give an example of how to persist cookies to disk with NSCoding, as the example link shows how to load them back. And how does this restore the server's session that was set ? This seems it restores the clients session – TMan Jan 17 '13 at 06:18