NSUserDefaults not get saved sometime

来源:互联网 发布:asp网络验证源码 编辑:程序博客网 时间:2024/06/06 05:00

If you terminate your app by pressing the home button (in theSimulator or on the device), your User Defaults will get saved.

If you terminate your app by pressing "Stop" in Xcode (in theSimulator or on the device), your UserDefaults might getsaved, but there's a good chance they won't. NSUserDefaultspersists any changes periodically, and if you terminate the processbefore they've been persisted, they'll be gone. You can force thesave by calling:

[[NSUserDefaults standardUserDefaults] synchronize];


Addendum:

In iOS4 (this answer was originally written when iOS3 was thepublic release), your User Defaults may not get saved when pressingthe home button. Manually calling [[NSUserDefaultsstandardUserDefaults]synchronize] in applicationDidEnterBackground: shouldensure that your User Defaults are saved correctly (this shouldreally be a built-in behaviour IMO).

0 0
原创粉丝点击