0

I'm using in-app settings from http://www.inappsettingskit.com/. It is really great but I can't figure out how to have the settings automatically load into the in-app settings on launch.

When I launch my app for the first time, all of the in-app multi-value cells are blank.

What I want to know is how to load them when the app is launched the first time?

The defaults are loaded in from the settings bundle, but aren't being passed through to the in-app settings...currently this is my code that does that...

-applicationDidFinishLaunching:

//It is here that we set the defaults
    NSString *textValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"title_key"];

    //If the first value is nil, then we know that the defaults are not set.
    if(textValue == nil)
    {
        //We set the default values from the settings bundle.

        //Get the bundle path
        NSString *bPath = [[NSBundle mainBundle] bundlePath];
        NSString *settingsPath = [bPath stringByAppendingPathComponent:@"Settings.bundle"];
        NSString *plistFile = [settingsPath stringByAppendingPathComponent:@"Root.plist"];

        NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:plistFile];
        NSArray *preferencesArray = [settingsDictionary objectForKey:@"PreferenceSpecifiers"];

        NSDictionary *item;

        NSString *title_Key;
        NSString *detail_Key;
        NSString *sort_Key;

        for(item in preferencesArray)
        {
            //Get the key of the item.
            NSString *keyValue = [item objectForKey:@"Key"];

            //Get the default value specified in the plist file.
            id defaultValue = [item objectForKey:@"DefaultValue"];

            if([keyValue isEqualToString:@"title_key"]) title_Key = defaultValue;
            if([keyValue isEqualToString:@"detail_key"]) detail_Key = defaultValue;
            if([keyValue isEqualToString:@"sort_key"]) sort_Key = defaultValue;

        }

        //Now that we have all the default values.
        //We will create it here.
        NSDictionary *appPrerfs = [NSDictionary dictionaryWithObjectsAndKeys:
                                   [NSNumber numberWithInt:2], @"title_key",
                                   [NSNumber numberWithInt:4], @"detail_key",
                                   [NSNumber numberWithInt:2], @"sort_key",
                                   nil];

        [[NSUserDefaults standardUserDefaults] registerDefaults:appPrerfs];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }

I have also tried the suggestion in the first answer, creating a seperate userDefaults.plist and have the defaults being loaded from there, my app is still getting the defaults but they are not passing through to in-app settings.

enter image description here

I thought that it should look like this on the first launching the app...

enter image description here

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
OscarTheGrouch
  • 2,374
  • 4
  • 28
  • 39

1 Answers1

1

You want to register your NSUserDefaults first. Check out this description.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
  • currently I have my defaults from the settings bundle being loaded in, with the code above. looking at your link, should I still create another way for the defaults to be loaded in? my app pulls the defaults from the code above on the first launch, but it is not pushing it into the in-app settings. – OscarTheGrouch Jun 26 '12 at 22:21
  • I have tried the suggestion in the first answer, creating a seperate userDefaults.plist and have the defaults being loaded from there, my app is still getting the defaults but they are not passing through to in-app settings. – OscarTheGrouch Jun 27 '12 at 10:20
  • You might wanna add a `[[NSUserDefaults standardUserDefaults] synchronize]` to make sure the new settings are synced to disk. I don't understand the code in your revised question. I assume it should somehow determine the NSUserDefaults based on your Settings.plist. But it just adds one key instead of all. I recommend going the route of an extra userDefaults.plist that you use at first start to register your NSUserDefaults. Way easier at least! – Ortwin Gentz Jun 27 '12 at 15:04
  • I had that in there... my issue was the code inside of my if statement was never being called. Once I changed my if statement it started working like it was suppose to. – OscarTheGrouch Jul 25 '12 at 03:01