Adding and Modifying the Settings Bundle IPHONE APPS

Xcode provides a template for adding a Settings bundle to your current project. The default settings bundle contains a Root. plist file and a default language directory for storing any localized resources. You can then expand this bundle to include additional property list files and resources needed by your Settings bundle.

Adding the Settings Bundle

To add a settings bundle to your Xcode project:

  1. Choose File > New File.
  2. Choose the iPhone OS > Settings > Settings Bundle template.
  3. Name the file Settings.bundle.

In addition to adding a new Settings bundle to your project, Xcode automatically adds that bundle to the Copy Bundle Resources build phase of your application target. Thus, all you have to do is modify the property list files of your Settings bundle and add any needed resources.

The newly added Settings.bundle bundle has the following structure:

Preparing the Settings Page for Editing

After creating your Settings bundle using the Settings Bundle template, you can format the contents of your schema files to make them easier to edit. The following steps show you how to do this for the Root.plist file of your Settings bundle but the steps are the same for any other schema files you create.

  1. Display the contents of the Root.plist file of your Settings bundle.
  2. a. In the Groups & Files list, disclose Settings.bundle to view its contents.
    b. Select the Root.plist file. Its contents appear in the Detail view.
  3. In the Detail view, select the Root key of the Root.plist file.
  4. Choose View > Property List Type > iPhone Settings plist.

This command formats the contents of the property list inside the Detail view. Instead of showing the property list key names and values, Xcode substitutes human-readable strings to make it easier to understand and edit the file’s contents.

Formatted contents of the Root.plist file

Formatted contents of the Root.plist file

Configuring a Settings Page: A Tutorial

This section contains a tutorial that shows you how to configure a Settings page to display the controls you want. The goal of the tutorial is to create a page like the one in Figure. If you have not yet created a Settings bundle for your project, you should do so as described in “Preparing the Settings Page for Editing” before proceeding with these steps.

A root Settings page

A root Settings page

  1. Change the value of the Settings Page Title key to the name of your application.
    Double-click the YOUR_PROJECT_NAME text and change the text to MyApp.
  2. Disclose the Preference Items key to display the default items that come with the template.
  3. Change the title of Item 1 to Sound:
    • Disclose Item 1 of Preference Items.
    • Change the value of the Title key from Group to Sound.
    • Leave the Type key set to Group.
  4. Create the first toggle switch for the newly renamed Sound group.
    • Select Item 3 of Preference Items and choose Edit > Cut.
    • Select Item 1 and choose Edit > Paste. (This moves the toggle switch item in front of the text field item.)
    • Disclose the toggle switch item to reveal its configuration keys.
    • Change the value of the Title key to Play Sounds.
    • Change the value of the Identifier key to play_sounds_preference. The item should now be configured as shown in the following figure.

    A root Settings page

  5. Create a second toggle switch for the Sound group.
    • Select Item 2 (the Play Sounds toggle switch).
    • Select Edit > Copy.
    • Select Edit >Paste. This places a copy of the toggle switch right after the first one.
    • Disclose the new toggle switch item to reveal its configuration keys.
    • Change the value of its Title key to 3D Sound.
    • Change the value of its Identifier key to 3D_sound_preference.
  6. At this point, you have finished the first group of settings and are ready to create the User Info group.

  7. Change Item 4 into a Group element and name it User Info.
    • Click Item 4 in the Preferences Items. This displays a drop-down menu with a list of item types.
    • From the drop-down menu, select Group to change the type of the element.
    • A root Settings page

    • Disclose the contents of Item 4.
    • Set the value of the Title key to User Info.
  8. Create the Name field.
    • Select Item 5 in the Preferences Item.
    • Using the drop-down menu, change its type to Text Field.
    • Set the value of the Title key to User Info.
    • Set value of the Identifier key to user_name.
    • Toggle the disclosure button of the item to hide its contents.
  9. Create the Experience Level settings.
    • Select Item 5 and click the plus (+) button (or press Return) to create a new item.
    • Click the new item and set its type to Multi Value.
    • Disclose the items contents and set its title to Experience Level, its identifier toexperience_preference, and its default value to 0.
    • With the Default Value key selected, click the plus button to add a Titles array.
    • Open the disclosure button for the Titles array and click the items button along the right edgeof the table. Clicking this button adds a new subitem to Titles.
    • Select the new subitem and click the plus button 2 more times to create 3 total subitems.
    • Set the values of the subitems to Beginner, Expert, and Master.
    • Select the Titles key again and click its disclosure button to hide its subitems.
    • Click the plus button to create the Values array.
    • Add 3 subitems to the Values array and set their values to 0, 1, and 2.
    • Click the disclosure button of Item 6 to hide its contents.
  10. Add the final group to your settings page.
    • Create a new item and set its type to Group and its title to Gravity.
    • Create another new item and set its type to Slider, its identifier to gravity_preference, its default value to 1, and its maximum value to 2.

Creating Additional Settings Page Files

The Settings Bundle template includes the Root.plist file, which defines your application’s top Settings page. To define additional Settings pages, you must add additional property list files to your Settings bundle.

You can do this either from the Finder or from Xcode.

To add a property list file to your Settings bundle in Xcode, do the following:

  1. In the Groups and Files pane, open your Settings bundle and select the Root.plist file.
  2. Choose File > New.
  3. Choose Other > Property List.
  4. Select the new file and choose View > Property List Type > iPhone Settings plist to configure it as a settings file.

After adding a new Settings page to your Settings bundle, you can edit the page’s contents as described in “Configuring a Settings Page: A Tutorial”. To display the settings for your page, you must reference it from a Child Pane element as described in “Hierarchical Preferences”.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status