Difference between revisions of "PreferenceBundles"

From iPhone Development Wiki
Jump to: navigation, search
m (Using a Preference Bundle: typo.)
m (Added to Preferences category)
Line 52: Line 52:
{{Navbox Library}}
{{Navbox Library}}
[[Category:Directories in /System/Library]]
[[Category:Directories in /System/Library]]

Revision as of 23:48, 7 September 2014

Preference Bundles are bundles for extending the Settings application. Developers can build their own bundles and place them in /Library/PreferenceBundles/ for others to use.

Structure of a Preference Bundle

Preference bundles must have the extension .bundle. The principle class of the bundle should be a subclass of PSListController or PSViewController. When providing localization files, if a specifier plist is called spec.plist, there should be a corresponding localization file called spec.strings. The bundle can have a 29×29 icon, with a preferred name of icon.png.

For more information on specifiers, see Preferences Specifier Plist Format.

Issues with OS 3.2 and 4.0

PSViewController underwent a massive change after 3.1, breaking all custom subclasses on the iPad and on 4.0 - it is now a UIViewController.

Improper implementations of PSListController subclasses will fail to work properly on 4.0 and later. You must set _specifiers within the - (id)specifiers method and return it. This is because PSListController relies on _specifiers to generate specifier metadata and group indices since iOS 4.0. Example:

- (id)specifiers {
	if (!_specifiers){
		_specifiers = [[self loadSpecifiersFromPlistName: kNameOfPreferencesPlist target: self] retain];
	return _specifiers;

Using a Preference Bundle

It is very common to load preferences in the constructor (%ctor) of your tweak.

static void loadPrefs() {
	NSMutableDictionary *settings = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/bundleID.plist"];

	logging = [settings objectForKey:@"logging_enabled"] ? [[settings objectForKey:@"logging_enabled"] boolValue] : NO;

%ctor {
    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadPrefs, CFSTR("bundleID/saved"), NULL, CFNotificationSuspensionBehaviorCoalesce);


It is very important to only load the preferences in the constructor and not access or modify any UI elements. If you need to do this, you can load your preferences in SpringBoard's init method.

More information about preferences can be seen here.