AFNetworking在会话中存储login用户
使用AFNetworking,我可以成功login,没有任何问题,并存储会话。 只要我停止debugging在Xcode,模拟器仍然是开放的,但进入iPhone的主屏幕。 当我再次从xcode运行应用程序,login会话消失,用户为零,花了几个小时,不知道为什么。 我的问题是停止debugging与会议的login用户? 是否使用setAuthorizationHeaderWithUsername必须处理任何事情。
@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; }
您需要将您的Cookie序列化到文件或其他商店。
看到这个答案 :