Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Ive got NSUserDefaults working fine in my app now, but upon doing a clean test I noticed that my app is missing default values for these defaults so they remain as blanks until the user sets them for the first time.
How can I put some actual default values in there for this first use of my app?
Post edited by trapper on
Black or Red - Possibly the first ever iPhone drinking game! Try it tonight.
In application did finish loading just check the value in the ones you are worried about and if null then set them to a default.
This is what I do and it works fine. The first time they install it sets about 6 or 7. I also run syncronize just after to ensure they are saved and updated.
BUZZER! : iTunes Library Music Quiz (1 or 2 Player)
You should up the defaults when your app loads. Then if there is a default file already setup fro the last time it will use those values. Otherwise it will use your preset defaults. save defaults when terminating so if the user has changed anything within your app it's saved.
Yeah I got the setting and getting of NSUserDefaults all working fine. The problem was starting off a new install with some pre-defined values. Do you mean I can do that using a plist in the setting.bundle? I thought this was for creating a new tab in the settings app.
Black or Red - Possibly the first ever iPhone drinking game! Try it tonight.
That still doesn't really show how you know if you should set default values in the first place. I'm actually running into this now, because I want to implement user settings without getting into sqlite (I know how to use sqlite, but this is already available).
The "check if null" would be great, but I most of my settings are integers, and you can't compare an integer to NULL.
edit: sorry, I read the class reference wrong, it seemed like this would always set the default values. This actually seems to work great, in that it doesn't overwrite the values once you change them.
There's no SQL involved. This is designed for defaults. You set them in your init. Then you load in any that you saved the last time. If none then your defaults are used. If there is a default file it's loaded and you use that. Save defaults when terminating.
I came upon this thread before finding another, more automatic way to initially setup the user defaults (that is, without relying on the Settings.app being opened by the user):
In a nut, this routine gets put in your applicationDidFinishLaunchingWithOptions: method and as soon as you app launches, it takes the DefaultValues from your settings bundle and makes them the selected value for each of your user defaults.
I came upon this thread before finding another, more automatic way to initially setup the user defaults (that is, without relying on the Settings.app being opened by the user):
In a nut, this routine gets put in your applicationDidFinishLaunchingWithOptions: method and as soon as you app launches, it takes the DefaultValues from your settings bundle and makes them the selected value for each of your user defaults.
Hope this helps someone in the future.
No, the way in your link is not the easiest/cleanest way.
There is a system call "registerDefaults" That lets you provide a dictionary of starting default values. The system automatically first looks for a user-specified setting. That overrides a starting value. Only if your app has not saved a new value, it then looks in the dictionary of starting values you provide in your call to registerDefaults.
The registerDefaults call is specifically for this situation.
Take a look at scottiphone's post, from earlier in this thread:
Replies
This is what I do and it works fine. The first time they install it sets about 6 or 7. I also run syncronize just after to ensure they are saved and updated.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome<a href="http://itunes.apple.com/WebObjects/MZStore.woa/
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesomesave defaults when terminating so if the user has changed anything within your app it's saved.
Page 204 in iPhone Programming Guide.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome<a href="http://itunes.apple.com/WebObjects/MZStore.woa/
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeNSNumber *testValue = [NSNumber numberWithFloat:1.0];
NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
testValue, @"MyTestValue" , ...
[defaults registerDefaults:appDefaults];
[appDefaults release];
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeThe "check if null" would be great, but I most of my settings are integers, and you can't compare an integer to NULL.
edit: sorry, I read the class reference wrong, it seemed like this would always set the default values. This actually seems to work great, in that it doesn't overwrite the values once you change them.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeNSUserDefaults nil Setting Problem - The B-Log
In a nut, this routine gets put in your applicationDidFinishLaunchingWithOptions: method and as soon as you app launches, it takes the DefaultValues from your settings bundle and makes them the selected value for each of your user defaults.
Hope this helps someone in the future.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeThere is a system call "registerDefaults" That lets you provide a dictionary of starting default values. The system automatically first looks for a user-specified setting. That overrides a starting value. Only if your app has not saved a new value, it then looks in the dictionary of starting values you provide in your call to registerDefaults.
The registerDefaults call is specifically for this situation.
Take a look at scottiphone's post, from earlier in this thread:
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome