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)?.
您可以使用以下代码清除NSUserDefault
。
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"yourkey"];
try to synchronize the user defaults
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"YourKey"];
[[NSUserDefaults standardUserDefaults] synchronize];yourkey
我建议编写一个迁移器例程,以在应用程序启动并分别更新默认数据库时检查某些以前的密钥。
您通常可以通过执行以下操作清除整个NSUserDefaults,以防万一您忘记了密钥或其他东西:
[[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]];
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.