How to Launch My Settings Bundle from My Application

How do I launch my settings bundle from my application?

They may have to go to the settings application, depending on how you do it.

See this document, the Applications Preferences section. Here's the relevant section from the introduction:

Adding your application preferences to the Settings application is most appropriate for productivity-style applications and in situations where you have preference values that are typically configured once and then rarely changed. For example, the Mail application uses these preferences to store the user’s account information and message-checking settings. Because the Settings application has support for displaying preferences hierarchically, manipulating your preferences from the Settings application is also more appropriate when you have a large number of preferences. Providing the same set of preferences in your application might require too many screens and might cause confusion for the user.

When your application has only a few options or has options that the user might want to change regularly, you should think carefully about whether the Settings application is the right place for them. For instance, utility applications provide custom configuration options on the back of their main view. A special control on the view flips it over to display the options and another control flips the view back. For simple applications, this type of behavior provides immediate access to the application’s options and is much more convenient for the user than going to Settings.

Update

The link has expired. This is a similar document on Settings bundles.

iPhone - how to put Settings bundle seen through System Settings App into your own App?

Yet another options:

  • MySettings

App settings bundle not showing up in settings app when using openurl

At the following link:

NSUserDafaults reading Root.plist got a nil value

Someone stated that "The values from settings.bundle do not actually load to NSUserDefaults until the user opens the settings for the first time. By default, they are off. Once the user opens the settings bundle, they will fill in for you."

and I believe some solutions were proposed here:

Can you make the settings in Settings.bundle default even if you don't open the Settings App

Such as this one from @Lawrence Johnston

- (void)registerDefaultsFromSettingsBundle {
[[NSUserDefaults standardUserDefaults] registerDefaults:[self defaultsFromPlistNamed:@"Root"]];
}

- (NSDictionary *)defaultsFromPlistNamed:(NSString *)plistName {
NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
NSAssert(settingsBundle, @"Could not find Settings.bundle while loading defaults.");

NSString *plistFullName = [NSString stringWithFormat:@"%@.plist", plistName];

NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:plistFullName]];
NSAssert1(settings, @"Could not load plist '%@' while loading defaults.", plistFullName);

NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
NSAssert1(preferences, @"Could not find preferences entry in plist '%@' while loading defaults.", plistFullName);

NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
for(NSDictionary *prefSpecification in preferences) {
NSString *key = [prefSpecification objectForKey:@"Key"];
id value = [prefSpecification objectForKey:@"DefaultValue"];
if(key && value) {
[defaults setObject:value forKey:key];
}

NSString *type = [prefSpecification objectForKey:@"Type"];
if ([type isEqualToString:@"PSChildPaneSpecifier"]) {
NSString *file = [prefSpecification objectForKey:@"File"];
NSAssert1(file, @"Unable to get child plist name from plist '%@'", plistFullName);
[defaults addEntriesFromDictionary:[self defaultsFromPlistNamed:file]];
}
}

return defaults;
}

How to change App's Setting Bundle settings before User opens app (only occurs after archiving)

You can accomplish this with a build phase run script.

Add a run script:

iOS Developer Doc

  1. In the project editor, select the target to which you want to add a
    run script build phase.
  2. Click Build Phases at the top of the project editor.
  3. Choose Editor > Add Build Phase > Add Run Script Build Phase.

Editor > Add Build Phase

Configure the script

in the Run Script template. Right under the shell input box is where you you add you script.

run script

Example script

You can use PlistBuddy in your script. Here is an example script that utilizes PlistBuddy to pull the CFBundleShortVersionString and the CFBundleVersion from the apps main Info.plist and adds them as the default values in the Settings bundle Root.plist.

Note: In this example script, the path to your projects Root.plist could be different. Also, the index of the PreferenceSpecifier needs to be changed to match the setup of your Root.plist file.

version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")

/usr/libexec/PlistBuddy "$SRCROOT/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:1:DefaultValue $version"
/usr/libexec/PlistBuddy "$SRCROOT/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:2:DefaultValue $build"

How to force application Settings bundle get updated?

Try cleaning and building. It seems that xcode caches dates and doesn't notice the change that your script is making. I've had similar things happen, clean always fixes it, but it is indeed a nuisance.

Edit my application settings.bundle's settings from iPhone app

1) You can change the value of settings app programmatically.

You need to call registerDefaults for changing the settings value programmatically like:

[defaults setObject:@"YES" forKey:@"Toggle];

store a setting then [defaults synchronize]; for saving the settings.

Here Toggle is the identifier given to any of the settings component.

2) Add your class as observer for NSUserDefaultsDidChangeNotification like:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changed) name:NSUserDefaultsDidChangeNotification object:nil];

- (void) changed
{
//change the app viewcontroller settings here
}

And change the viewControllers settings in the above method.

How can you launch a URL from the iOS Settings Bundle?

You can't. Current Settings.bundle is able to only display or change values. Better check Apple docs Settings Application Schema Reference and the few available element types. Sorry.

Add my app to tvOS app settings screen

There isn't a Settings Bundle in tvOS section in Xcode, but you can select the Settings Bundle from iOS section, it's a bit tricky but it definitely works.

1. File -> New -> File

2. iOS -> Resource -> Settings Bundle

Settings Bundle from iOS Section

3. Edit your Bundle Settings plist

4. Build and Run

N.B. tvOS and Xcode 7.1 now is in beta, maybe Apple will add "Settings Bundle" item in tvOS section in the stable release.



Related Topics



Leave a reply



Submit