AFNetworking在会话中存储已登录的用户 [英] AFNetworking Storing Logged in User in session
问题描述
使用AFNetworking,我可以成功登录而不会出现任何问题并存储会话。一旦我停止在xcode中进行调试,模拟器仍处于打开状态,但转到iPhone主屏幕。当我从xcode再次运行该应用程序时,登录会话消失了,用户为零,花了几个小时,不知道为什么。我的问题是停止调试已登录用户的会话吗?
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;
登录名:
[[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序列化到文件或其他存储中。
You need to serialize your cookies into files or other stores.
请参见此答案:
这篇关于AFNetworking在会话中存储已登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!