0

updated IOS app with changes in NSUser default keys ( added few more keys and changed some existing key names) app is crashing at initialization time after updating from store . If I delete the app completely and reinstall it then it is working fine . We can not clear previous NSUser defaults and recreate it when updating app ( I mean complete re-installation by writing some logic in updated app)?.

5 Answers5

0

You can clear NSUserDefault with below code.

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"yourkey"];
Rahul Patel
  • 5,858
  • 6
  • 46
  • 72
iPhone developer.
  • 2,122
  • 1
  • 16
  • 17
0

try to synchronize the user defaults

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"YourKey"];
[[NSUserDefaults standardUserDefaults] synchronize];yourkey
swapnali patil
  • 304
  • 2
  • 17
0

I'd recommend to write a migrator routine which checks for certain former keys when the application launches and updates the defaults database respectively.

vadian
  • 274,689
  • 30
  • 353
  • 361
0

you can usuually clean out the entire NSUserDefaults by doing this, just in case you forgot the key or something:

   [[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary]  forName:[[NSBundle mainBundle] bundleIdentifier]];
Larry Pickles
  • 4,615
  • 2
  • 19
  • 36
0

You can check if app is opening for first time then clear NSUserDefault as below

[[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary]  forName:[[NSBundle mainBundle] bundleIdentifier]];

After that set your NSUserDefault again as per your requirement.

Rahul Patel
  • 5,858
  • 6
  • 46
  • 72