In: This Question it is said AFNetworking
takes care of cookies automatically in the background, but in a Previous question I asked, I was having trouble keeping the session on the server that was made in php when I logged in. Once I closed(stop debugging in Xcode) the app and went back in the session was gone. The answer was to persist cookies like so to fix the problem:
NSData *cookiesData = [[NSUserDefaults standardUserDefaults] objectForKey:@"User"];
if ([cookiesData length] > 0) {
for (NSHTTPCookie *cookie in [NSKeyedUnarchiver cookiesData]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
}
}
This gives me an app crash when I try to do something like this. When I log in I set the NSUserDefault like so:
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"User"];
//Then synthesize
Is this the wrong way to use this? Is NSHTTPCookieStorage even my problem? Thanks.
NSUserDefaults
is a terrible idea because it is stored unencrypted in the app sandbox. Consider using Keychain instead – Themis