i created a simple project, with a "+" and "-" buttons that increase or decrease a number inside a label.
I wanted to test the registerDefaults method, but if i click on the "home" button, and come back on the project from the simulator (with my app's icon), the number is still the same on screen.
How can i test the user settings with this example? or is it something with the simulator, or would it work if i use the device and wait for the memory warning method to automatically refresh the project, and then it would work?
here's a bit of my code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
NSNumber *testValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"kRestore"];
if (testValue){
NSLog(@"already");
viewController.myNum = (int)testValue;
} else {
NSLog(@"empty");
viewController.myNum = 0;
}
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
NSNumber *num = [NSNumber numberWithInt:viewController.myNum];
NSDictionary *savedNumber = [NSDictionary dictionaryWithObject:num forKey:@"kRestore"];
[[NSUserDefaults standardUserDefaults] registerDefaults:savedNumber];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"ok resign active");
}
Thanks