I have a sandboxed app for OSX and I saved some data in NSUserDefaults
, everything was fine until I deleted the plist file from the ~Library/Preferences/ directory.
I thought the app should recreat it but it did not. When I debug I see that
[[NSUserDefaults standardUserDefaults] synchronize]
method returns YES
and data are saved in the class but when I restart the app user defaults is empty.
Even if I copy those plist file from backup to the Preferences directory, the app does not see it.
Of course the plist should be saved in the Containers/my app bundle id/Data/Library/Preferences and when I copy the plist file from backup to that directory, the app can see it, but why that file is not recreated when I deleted it?
Does anybody know why is that?
All the contents saved by NSUserDefaults is saved inside a plist file that can be found under Library -> Preferences -> $AppBundleId.
Navigate to AppData -> Library -> Preferences. The property list file (. plist) in this folder is the database file of the standard UserDefaults of your app.
Storing Data in User Defaults The user's defaults database is stored on disk as a property list or plist. A property list or plist is an XML file. At runtime, the UserDefaults class keeps the contents of the property list in memory to improve performance.
It appears the limit is the maximum file size for iOS (logically), which is currently 4GB: https://discussions.apple.com/thread/1763096?tstart=0. The precise size of the data is circumscribed by the compiler types (NSData, NSString, etc.) or the files in your asset bundle.
Check this question - might be related to caching or prefs location when running in the sandbox:
Mac sandbox created but no NSUserDefaults plist
I had this problem, which is caused by deleting the files manually. What you can do instead is to use the defaults
terminal command. This way I was able to reset the defaults without breaking things. Replace "bundle-identifier" with your bundle id.
To view the current values:
defaults read bundle-identifier
To remove stored values:
defaults delete bundle-identifier
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With