Reputation: 16430
I'm working at the beta version of my App and i need to be sure that at first launch of the final release users that have been beta tester will start the application with a completely clear user default set... (i can't change the Bundle ID).
1) Is there a way to clear user defaults programmatically ?
2) Will sandboxing this App for the App Store submission helps me ?
Upvotes: 4
Views: 2062
Reputation: 61238
What's wrong with +[NSUserDefaults resetStandardUserDefaults]? If you've registered your defaults properly, this single line will reset to the registered defaults you provided.
Upvotes: 2
Reputation: 5054
You can remove it like this:
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
To run it on your first launch, I would just set a BOOL flag. One way to do it is as follows:
- (void)applicationDidFihishLaunching
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if ([[prefs objectForKey:@"secondOrMoreTimeLoading"]boolValue]==0) //so if there is nothing there...
{
NSLog(@"This is the first time the user has loaded the application. Welcome!");
//run the code above here, then change our flag to 1 so that it never runs this again (unless the prefs are reset elsewhere)
[prefs setObject:[NSNumber numberWithBool:1] forKey:@"secondOrMoreTimeLoading"];
}
else{NSLog(@"Welcome back, user.");}
}
Upvotes: 4