2013-01-17 39 views
1

使用AFNetworking,我可以成功登錄,沒有任何問題並存儲會話。只要我停止在xcode中調試,模擬器仍然打開,但會進入iphone主屏幕。當我再次從xcode運行應用程序時,登錄會話消失,用戶爲零,花了幾個小時,不知道爲什麼。我的問題是停止調試與登錄用戶的會話混亂?是否使用setAuthorizationHeaderWithUsername必須處理任何事情。AFNetworking在會話中存儲登錄用戶

@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; 

} 

回答

0

你需要序列化你的cookies到文件或其他商店。

this answer

+0

THX的響應,沒有什麼辦法可以給出如何堅持餅乾到磁盤NSCoding一個例子,作爲例如鏈接顯示瞭如何將它們加載回來。這又如何恢復已設置的服務器會話?這似乎會恢復客戶端會話 – TMan