Monday, April 11, 2011

Easy Way to Create Settings View

Most applications need settings or at least a way to display version number. In theory it's very simple: just show a short list with a few hardcoded rows. It could be difficult, but since "settings" is such a common use case, Apple iOS SDK offers special support. It's not quite perfect, so let's check the possibilities.

There are a few ways to display a standard settings view for application. Apple recommended way is to "De-emphasize Settings", meaning you should show them in global iPhone Settings, found via... well, the Settings application.

It's a big list: first there are device connectivity settings, followed by device settings and built-in application settings. Finally in the 4th section you will get to the alphabetical list of 3rd party application settings. That can be very long.

iOS SDK offers special support to put your settings into Settings application. Open Xcode, select the project and right click, choose "New File..." from menu to open file template view. Choose iOS - Resource - Settings Bundle and that's about it. Default name "Settings.bundle" makes your settings visible in Settings application.

Regardless of what Apple says, putting settings inside your application is the only way to make sure users will find them. You can do this by creating a custom view and filling all the data manually. It's a lot more work than Apple recommended way, but you can customize your settings view to fit the style of the application. For inspiration, check these great screenshots at pttrns.

Wouldn't it be wonderful, if iOS SDK would support Settings.bundle inside your application? Easy way to create and modify settings, easy way to display them? That's what Luc Vandal at Edovia and Ortwin Gentz at FutureTap thought and created an open source InAppSettingsKit package! Check the sample application, there are even some additional features compared to standard settings.bundle.

To integrate InAppSettingsKit into your own application, select your project in Xcode and right click. Select "Add Files...", navigate to folder where you downloaded and opened the library and choose the InAppSettingsKit folder. Now you have to choose very carefully: do you want to "copy items into destination group's folder (if needed)":

Yes means all source code needed to compile your application is in same location. Easy to backup, easy to handle version control, easy to transfer.

No means that it's easier to download library updates from git-hub, easier to share same library between several applications, easier to fix possible bugs or create experimental enhansements. Choose carefully and make sure you remember which one you chose!

Finally here's as an example Root.plist XML for the image at the beginning of this post. Open Settings.bundle in Xcode, select Root.plist, right click and choose Open as - source code from menu.
<?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>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>Title</key>
            <string>Settings</string>
            <key>Type</key>
            <string>PSGroupSpecifier</string>
        </dict>
        <dict>
            <key>Type</key>
            <string>PSMultiValueSpecifier</string>
            <key>Title</key>
            <string>Message format</string>
            <key>Key</key>
            <string>msgFormat</string>
            <key>DefaultValue</key>
            <integer>1</integer>
            <key>Values</key>
            <array>
                <integer>1</integer>
                <integer>2</integer>
            </array>
            <key>Titles</key>
            <array>
                <string>Short</string>
                <string>Full</string>
            </array>
            <key>FooterText</key>
            <string>Short: time and message,
Full: everything</string>
        </dict>
        <dict>
            <key>Title</key>
            <string>About</string>
            <key>Type</key>
            <string>PSGroupSpecifier</string>
            <key>FooterText</key>
            <string>Copyright © 2011 by Jomnius.
All rights reserved.</string>
        </dict>
        <dict>
            <key>DefaultValue</key>
            <string>1.0</string>
            <key>Key</key>
            <string>version_string</string>
            <key>Title</key>
            <string>Version</string>
            <key>Type</key>
            <string>PSTitleValueSpecifier</string>
        </dict>
        <dict>
            <key>DefaultValue</key>
            <string>Jouni Miettunen</string>
            <key>Key</key>
            <string>version_string1</string>
            <key>Title</key>
            <string>Developed by</string>
            <key>Type</key>
            <string>PSTitleValueSpecifier</string>
        </dict>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>
</plist>

1 comment: