Вопрос

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

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top