Automatically delete user defaults in OS X

I am working on a beta version of my application, and I need to be sure that the first time the final version is launched, users who were a beta tester started the application with a fully understandable user set by default ... (i cannot change the Bundle identifier).

1) Is there a way to programmatically change user defaults?

2) Does the sandbox for this application help for presentation on the App Store?

+4
source share
2 answers

You can remove it like this:

NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; 

To start it on the first start, I would just set the BOOL flag. One way to do this:

 - (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.");} } 
+4
source

What happened to + [NSUserDefaults resetStandardUserDefaults] ? If you registered your default settings, this single line will reset for the default values ​​you registered.

+2
source

Source: https://habr.com/ru/post/1381571/


All Articles