AFNetworking Storing Logged in User in session

让人想犯罪 __ 提交于 2019-12-11 11:49:56

问题


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;

}

回答1:


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

See this answer:



来源:https://stackoverflow.com/questions/14372817/afnetworking-storing-logged-in-user-in-session

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