使用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;
}