Get NSUserDefaults plist file from device

When testing my application on a simulator, I like the ability to edit or even garbage a plist application file (which contains NSUserDefaults) from the iPhone Simulator folder. This is useful for testing (for example, your application stores the dictionary there, but you change the model / keys that you use for this data, and therefore you need to delete the dictionary).

Is it possible to access this file on the device (for your own application) without jailbreak?

Thanks in advance

+5
source share
2 answers

Library/Preferences. <iOS application target identifier>.plist ( ) :

NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];

#ifdef env:

#ifdef TESTING
    // use the code provided by tsakoyan below
#endif
+5

NSUserDefaults, /

 NSDictionary *userDefDic = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
 NSArray *keys = [NSArray arrayWithArray:[userDefDic allKeys]];
 for (NSString *key in keys) {
     [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
 }
 [[NSUserDefaults standardUserDefaults] synchronize]; 
+3

All Articles