I have a Root.plist file which is used for my app's settings. It has a toggle switch with an identifier of reset_achievements_preference
. In the applicationDidBecomeActive
method, I have this code:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(@"reset achievements: %i", [[NSUserDefaults standardUserDefaults] boolForKey:@"reset_achievements_preference"]);
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"reset_achievements_preference"]) {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"reset_achievements_preference"];
[[NSUserDefaults standardUserDefaults] synchronize];
//Code to react to this change
}
}
Sometimes it hits the NSLog and notices the object change, but sometimes it doesn't. I wonder if I'm dealing with this incorrectly?
Try adding:
To
applicationDidBecomeActive:
before anything else to refresh the status of the user defaults. Thysynchronize
method is called periodically by the application, but you can refresh it manually.