Question

I have been trying to use the Settings.bundle as the store for options using PSMultiValueSpecifier which will allow a user to select one of them. So I need to be able to add NEW options in the Settings.bundle. Seemed easy enough.

Here is a sample of the PSMultiValueSpecifier in the Root.plist

<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>Options</string>
<key>DefaultValue</key>
<string></string>
<key>Key</key>
<string>optionSelection_preference</string>
<key>Values</key>
<array>
    <string>option_1_key</string>
</array>
<key>Titles</key>
<array>
    <string>Option 1</string>
</array>

So I am trying to add 'Option 2' and it's key. So I wrote the following code (partial):

NSDictionary* rootPlist = [NSDictionary dictionaryWithContentsOfFile:settingsBundle];

if (rootPlist == nil)
    return NO;

NSArray* specifiers = [rootPlist objectForKey:@"PreferenceSpecifiers"];

NSMutableDictionary *multiValueSpecifier = nil;

for (NSMutableDictionary *specifier in specifiers)
    {
    if ([[specifier objectForKey:@"Key"] isEqualToString:speficierKey] == YES && [[specifier objectForKey:@"Type"] isEqualToString:@"PSMultiValueSpecifier"] == YES)
        {
        multiValueSpecifier = specifier;
        break;
        }
    }

if (multiValueSpecifier == nil)
    return NO;

NSMutableArray* titlesArray = [[multiValueSpecifier objectForKey:@"Titles"] mutableCopy];
NSMutableArray* valuesArray = [[multiValueSpecifier objectForKey:@"Values"] mutableCopy];

[titlesArray addObject:title];
[valuesArray addObject:value];

[multiValueSpecifier setObject:titlesArray forKey:@"Titles"];
[multiValueSpecifier setObject:valuesArray forKey:@"Values"];

return [rootPlist writeToFile:settingsBundle atomically:YES];

The code seems to work and I see the changes in the Settings.bundle.

PROBLEM: When re-loaded, the new entry is gone, and only the entry added from XCode remains.

Was it helpful?

Solution

This won't work in an App Store app anyway. You can't modify the Settings bundle because that would modify the contents of the app bundle which is not allowed for App Store apps because it would invalidate their signature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top