AFNetworking存储在会话中登录用户

时间:2013-01-17 05:39:14

标签: ios session cookies afnetworking

使用AFNetworking,我能够毫无问题地成功登录并存储会话。一旦我停止在xcode中调试,模拟器仍然打开但进入iphone主屏幕。当我再次从xcode运行应用程序时,登录会话消失,用户为零,花了几个小时,不知道为什么。我的问题是停止调试与登录用户的会话混乱?使用setAuthorizationHeaderWithUsername是否与任何事情有关。

  @property (retain, nonatomic) NSDictionary* user;

登录:

      [[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 个答案:

答案 0 :(得分:0)

您需要将Cookie序列化为文件或其他商店。

请参阅this answer