I have an apps that load a json from a remote server, using a NSURLConnection. Once it has finished loading (calling connectionDidFinishLoading), I want to record if it was the first launch of the application.
So in connectionDidFinishLoading I did that :
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL firstLaunch = [defaults boolForKey:@"screen_firstLaunch"];
NSLog(@"First launch : %d",firstLaunch);
[defaults setBool:YES forKey:@"screen_firstLaunch"];
And it displays “First launch : 0” every time ….
So I thought it might be because it’s on another thread, so I try to deport the code into a function that I call in connectionDidFinishLoading using performSelectorOnMainThread, but I get the same result …
Please someone help me, I’m going mad !
Remember to call
[defaults synchronize];after setting your key in the defaults.