When testing my app on the simulator, I like the ability to edit, or even trash the apps plist file (which contains the NSUserDefaults) from the iPhone Simulator folder. This proves useful when testing (e.g. your app stores a dictionary in there, but you change the model/keys that you use for this data, and therefore need to remove the dictionary stored).
Is it possible to access this file on device (for your own app), without jailbreak?
Thanks in advance
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.
There isn't a way to check whether an object within NSUserDefaults is empty or not. However, you can check whether a value for particular key is nil or not.
The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user's preferences. For example, you can allow users to specify their preferred units of measurement or media playback speed.
The file is in Library/Preferences
. The file is a binary plist with name <iOS application target identifier>.plist
(look for the Identifier field in your app target settings), or list the directory contents:
NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
You could also load clean defaults with a #ifdef
macro based on some env variable:
#ifdef TESTING
// use the code provided by tsakoyan below
#endif
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