NSUserDefaults saves details sometimes and doesn&#

2019-07-20 06:40发布

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条回答
干净又极端
2楼-- · 2019-07-20 07:18

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];
}
查看更多
登录 后发表回答