Difference between revisions of "PreferenceLoader"

From iPhone Development Wiki
Jump to: navigation, search
m (wikify.)
Line 98: Line 98:
  
 
The difference here is that instead of loading Test.plist, this entry will load the <tt>TestSettings.bundle</tt> located at <tt>/System/Library/PreferenceBundles/</tt>. Unlike the simple method, all of the files except <tt>TestSettings.plist</tt> are located inside the bundle. A skeleton PreferenceBundle project can be found at http://www.volatile-dev.com/PreferenceLoader/TestSettings.zip
 
The difference here is that instead of loading Test.plist, this entry will load the <tt>TestSettings.bundle</tt> located at <tt>/System/Library/PreferenceBundles/</tt>. Unlike the simple method, all of the files except <tt>TestSettings.plist</tt> are located inside the bundle. A skeleton PreferenceBundle project can be found at http://www.volatile-dev.com/PreferenceLoader/TestSettings.zip
 +
 +
== PreferenceLoader 1.2 Changes ==
 +
 +
PreferenceLoader 1.2 now supports sub-folders of the <tt>/Library/PreferenceLoader/Preferences/</tt>
 +
folder. These sub folders are similar to a PreferenceBundle, except they contain no executable code. This approach allows developers to create more complex settings pages with multiple plists and localization without the need for writing code. This approach functions exactly the same as the basic approach from the previous version of PreferenceLoader, except the entry dictionary is moved into a plist file inside the sub-folder.
 +
 +
Additionally, PreferenceLoader 1.2 has added support for locating PreferenceBundles externally to <tt>/System/Library/PreferenceBundles/</tt>. PreferenceBundles may now be placed in <tt>/Library/PreferenceLoader/PreferenceBundles/</tt>. This approach follows the same pattern as the sub-folder approach, in that the entry dictionary must be in a plist file located inside the bundle. <b>Entries located in <tt>/Library/PreferenceLoader/Preferences/</tt> can only reference bundles in <tt>/System/Library/PreferenceBundles/</tt></b>.
  
 
{{Navbox Library}}
 
{{Navbox Library}}
 
[[Category:Directories in /Library]]
 
[[Category:Directories in /Library]]

Revision as of 06:45, 24 November 2009

PreferenceLoader
PrefLoaderScreenshot.png
Cydia Package
Developer Thomas Moore (volatile-dev)
Package ID preferenceloader
Latest Version 1.1


PreferenceLoader is a MobileSubstrate based utility that allows developers to add entries to the Settings app, similar to the Settings bundles that AppStore apps use.

The approach PreferenceLoader takes is different that other approaches in that the Settings plist files are not modified on disk. Entries are dynamically added to the list when the Settings app is loaded. PreferenceLoader gives the developer two options for entries. The first option is to simply create a single plist with basic options like PSSwitchCell or PSEditTextCell. The second option is allows the developer to create a full-blown PreferencesBundle.

Regardless of the approach taken, each new entry is specified in its own plist located at /Library/PreferenceLoader/Preferences/. The plist must contain a dictionary containing a dictionary element named entry, as shown TestSettngs.plist:

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
          <key>entry</key>
          <dict>
                <key>cell</key>
                <string>PSLinkCell</string>
                <key>icon</key>
                <string>TestIcon.png</string>
                <key>label</key>
                <string>Test</string>
          </dict>
    </dict>
    </plist>

In this example, a new entry with the label "Test" is created that links to the settings page defined in Test.plist using the icon TestIcon.png. Both of these files should be placed in the Preferences directory with TestSettings.plist. One interesting thing that can be done is to combine the entry plist with the settings plist. This works because the settings plist has elements named items and title, so adding an entry element does not break anything. Here's an example of Test.plist that is combined:

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
          <key>entry</key>
          <dict>
                <key>cell</key>
                <string>PSLinkCell</string>
                <key>icon</key>
                <string>TestIcon.png</string>
                <key>label</key>
                <string>Test</string>
          </dict>
          <key>items</key>
          <array>
                 <dict>
                      <key>cell</key>
                      <string>PSSwitchCell</string>
                      <key>default</key>
                      <true/>
                      <key>defaults</key>
                      <string>com.test.TestSettings</string>
                      <key>key</key>
                      <string>testKey</string>
                      <key>label</key>
                      <string>Test Setting</string>
                </dict>
          </array>
          <key>title</key>
          <string>Test</string>
    </dict>
    </plist>

There is a good tutorial on how to create these settings plists on MMi at http://modmyi.com/forums/file-mods/22453-how-make-custom-menus-preferences-app-custom-preferences.html.

PreferenceBundles

For those of you that want to create more complex settings pages, then the PreferenceBundles is for you. With this technique, you can actually create custom pages that are able to execute code. Skylar Cantu has put together a very useful guide on PreferenceBundles at http://www.touchrepo.com/guides/preferencebundles/PreferenceBundles.doc

The only difference to his guide that is to be noted is that like the simple approach given above, the developer should create a plist in /Library/PreferenceLoader/Preferences/. Here's an example of an updated TestSettings.plist:

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
          <key>entry</key>
          <dict>
                <key>bundle</key>
                <string>TestSettings</string>
                <key>cell</key>
                <string>PSLinkCell</string>
                <key>icon</key>
                <string>TestIcon.png</string>
                <key>isController</key>
                <true/>
                <key>label</key>
                <string>Test</string>
          </dict>
    </dict>
    </plist>

The difference here is that instead of loading Test.plist, this entry will load the TestSettings.bundle located at /System/Library/PreferenceBundles/. Unlike the simple method, all of the files except TestSettings.plist are located inside the bundle. A skeleton PreferenceBundle project can be found at http://www.volatile-dev.com/PreferenceLoader/TestSettings.zip

PreferenceLoader 1.2 Changes

PreferenceLoader 1.2 now supports sub-folders of the /Library/PreferenceLoader/Preferences/ folder. These sub folders are similar to a PreferenceBundle, except they contain no executable code. This approach allows developers to create more complex settings pages with multiple plists and localization without the need for writing code. This approach functions exactly the same as the basic approach from the previous version of PreferenceLoader, except the entry dictionary is moved into a plist file inside the sub-folder.

Additionally, PreferenceLoader 1.2 has added support for locating PreferenceBundles externally to /System/Library/PreferenceBundles/. PreferenceBundles may now be placed in /Library/PreferenceLoader/PreferenceBundles/. This approach follows the same pattern as the sub-folder approach, in that the entry dictionary must be in a plist file located inside the bundle. Entries located in /Library/PreferenceLoader/Preferences/ can only reference bundles in /System/Library/PreferenceBundles/.