NSUserDefaults saves details sometimes and doesn't someother times

不羁的心 提交于 2019-12-11 03:43:54

问题


I use NSUserDefaults to save some data locally. But the problem is it doesn't save the data all the times.

For instance:

While an app is crashing I save the execption related informations using NSUserDefaults

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSSetUncaughtExceptionHandler(&onUncaughtException);

}

void onUncaughtException(NSException* exception)
{
 //save exception related details using NSuserdefaults
}

回答1:


The problem is that you have to synchronize thne NSUserDefaults while crashing.Since you are not doing that, the exception details disappear

Call the synchronize method on app termination:

- (void)applicationWillTerminate:(UIApplication *)application
{
       [[NSUserDefaults standardUserDefaults] synchronize];
}


来源:https://stackoverflow.com/questions/25229276/nsuserdefaults-saves-details-sometimes-and-doesnt-someother-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!