I'm wondering if there's anywhere i can see what data is in my NSUserDefaults? Like, how does it works? Is there a file that stores in my iphone that contains all the data in the NSUserDefaults or is the file stores in different apps? If i have set [NSUserDefaults standardUserDefaults] setObject:someString forKey:@"someString"];
in app A, can i use NSString *listData = [[NSUserDefaults standardUserDefaults] stringForKey:@"someString"]
to get the string in another app B? Is there somewhere the NSUserDefaults is physically stored?
views:
28answers:
3
+1
A:
The preferences of your app are stored in a .plist file (in binary format) in [APP_BASE_DIR]/Library/Preferences/
.
See ~/Library/Application Support/iPhone Simulator/4.1/Applications
to see the app base dirs in the iPhone Simulator.
Ole Begemann
2010-10-19 17:47:27
A:
The NSUserDefaults is stored in a plist file; on the iPhone and iPad, you cannot simply open these files. However, you can have your app print out the contents to the debugger.
Richard
2010-10-19 18:26:51
A:
I believe sandboxing will prevent accessing another application's user defaults under iOS. Under Mac OS X, you can work with another application's user defaults by dropping down to the CFPreferences
API:
/* ownership follows the Create/Copy rule, so must release when done -
* here, I just autorelease */
NSString *
value = [(id)CFPreferencesCopyAppValue(CFSTR("key"), CFSTR("com.foo.otherapp"))
autorelease];
if ([value isKindOfClass:[NSString class]]) {
/* use the string */
}
Jeremy W. Sherman
2010-10-19 18:59:26