NSUserDefaults changed IOS app crashing after update

854 views Asked by At

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

There are 5 answers

0
Larry Pickles On

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]];
0
iPhone developer. On

You can clear NSUserDefault with below code.

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"yourkey"];
0
swapnali patil On

try to synchronize the user defaults

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"YourKey"];
[[NSUserDefaults standardUserDefaults] synchronize];yourkey
0
vadian On

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

0
Rahul Patel On

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.