0

I'm developing an iOS app with latest SDK.

I have created a Settings.bundle with a Root.plist and another four .plist and every setting on these files have each default value.

This is the first time I work with Settings.bundle and I'm lost. I have found this question where they said that I have to read Settings.bundle defaults values every time I run the application and I don't understand why.

I think I have to continue using NSUserDefaults here to read settings values.

I have these questions:

  1. How can I read the values set on these settings using Setting app?
  2. How can I know if the user changes one or more of these values? The user makes the app to goes background, open Setting app and change something. How can I know that programmatically?
  3. How can I save any modification (a change in a setting value) and see that change on Settings app?

By the way, now I have this code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    // Set the application defaults
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if (![defaults boolForKey:@"firstRun"])
    {
        NSDictionary *appDefaults = [PreferenceDefaultValues dictionary];
        [defaults registerDefaults:appDefaults];

        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstRun"];

        [defaults synchronize];
    }

    return YES;
}

1 Answer 1

3
  1. The identifier of any preference item in the Settings.bundle plist can be accessed with NSUserDefaults. For example, if you have a preference item with an identifier named allowDiagnostics, then you can access the value for that item with [NSUserDefaults standardUserDefaults] boolForKey:@"allowDiagnostics"] (assuming that it was a BOOL item).

  2. You can use the NSUserDefaultsDidChangeNotification to get notified of any changes to your preferences.

  3. The same way you read them. To continue the example of 1, [NSUserDefaults standardUserDefaults] setBool:YES forKey:@"allowDiagnostics"]. Note though, that allowing the user to change options from multiple places (Settings.bundle and somewhere in your app), can be confusing to the user.

2
  • Thanks for your answer. Do I have to do [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults]; every time my app starts?
    – VansFannel
    Mar 12, 2013 at 6:31
  • I usually put that line of code in my applicationDidFinishLaunching:withOptions Mar 12, 2013 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.