It seems something is going wrong, I can't store or read NSUserDefaults in my code:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray * defaultKeys = [NSArray arrayWithObjects:
@"FirstViewComposer",
@"ProfileNickname",
@"ProfileGender",
@"ProfileDateOfBirth",
@"ProfileFavoriteColor",
@"ProfileHeight",
nil];
NSArray * defaultValues = [NSArray arrayWithObjects:
@"YES",
@"Me",
@"Male",
@"08 Dec 1983"
@"Red",
@"183",
nil];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:defaultValues forKey:defaultKeys];
[defaults registerDefaults:appDefaults];
NSLog(@"%@", [defaults stringForKey:@"FirstViewComposer"]); //null
thanks
UPDATE : Now I'm synchronized, actually they are stored but I'm probably not retrieving them correctly:
2011-08-23 17:16:06.932 Sansnuage[1404:b603] defaults: (
(
en,
fr,
de,
ja,
nl,
it,
es,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ko,
"zh-Hans",
"zh-Hant",
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
"en-GB",
ca,
hu,
vi
),
1,
(
YES,
Me,
Male,
"08 Dec 1983Red",
183
),
"en_US",
(
"en_US@hw=US;sw=QWERTY"
),
(
en,
fr,
de,
ja,
nl,
it,
es,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ko,
"zh-Hans",
"zh-Hant",
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
"en-GB",
ca,
hu,
vi
),
macintosh
)
You have to synchronize your data before retrieve them from disk. To do so you should use synchronize method.
UPDATE: You should change the way you try to store your appDefaults NSDictionary. Try:
#define kAppDefaultEnty @"AppDefaultsEntry"
[defaults setObject:appDefaults forKey:kAppDefaultEnty];
And then synchronize it:
[defaults synchronize];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.