本文介绍了NSUserDefaults有时会保存详细信息,也不会有其他时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用NSUserDefaults在本地保存一些数据。但是问题是它不会一直保存数据。
I use NSUserDefaults to save some data locally. But the problem is it doesn't save the data all the times.
例如:
虽然应用程序崩溃我使用NSUserDefaults保存与execption相关的信息
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
}
推荐答案
问题是你必须 / code> thne
NSUserDefaults
同时崩溃。因为你没有这样做,异常细节消失
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];
}
这篇关于NSUserDefaults有时会保存详细信息,也不会有其他时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!