Application Settings Bundle Part – I

I am going to illustrate “How to add Settings Bundle for application & we’ll see how to access those settings from within our Application.”

The Settings application lets the user enter and change preferences for any application that has a settings bundle. A settings bundle is a group of files build into an application that tells the Settings application what preferences the application wants to collect from the user.

User Defaults is the part of Application Preferences that stores and retrieves preferences. The Settings application acts as a common user interface for the iPhone’s User Defaults. User Defaults is implemented by NSUserDefaults class.

We’re going to create an application, add and configure a settings bundle. Then we’ll access and edit those preferences from within our application.

To make Settings application, we don’t have to design a user interface for the preferences. We just create a property list defining our application’s available settings. The Settings application settings the interface for us. There are limits, however, to what we can do with the Settings application. Any preference that the user might need to change while our application is running should not be limited to the Setting application.

Immersive applications, like games, generally should provide their own preferences view so that the user doesn’t have to quit in order to make some changes.

Below is the some step follow to build up the Setting Bundle

Step 1: Create new project and choose the “Utility Application” or you can use the “Single View Application” etc..

Step 2 : Give the name of the application and choose the device in which you want to develop.

 

step 3 : When press the next button choose the location where store the project.

step 4 : Then starts the project which shows below like screen.

Step 5 : Now add the setting-bundle to our project for that click on the project root object, AppSettings, and select New File….

 

Step 6 : Now Choose the “Settings Bundle” and give the name of the bundle by default “Settings.bundle”.

 

Step 7 : After adding the bundle into project it shows like below screen.

Step 8 : Now changes into the Settings Up Property List

Let’s look at the property list either using Xcode’s property list editor or Property List Editor application.

Property lists all have a root node which is a Dictionary node type. All of the children of Dictionary node need to have both a key and a value.

There are several different types of nodes: Dictionary nodes, Array nodes. These are the only property list node types that can contain other nodes. There are also a data node types such as Boolean, Data, Date, Number, and String.

When creating a setting property list, we should follow a defined format. The one we’ve just made, Root.plist, is a properly formatted property list.

Let’s expand the PreferenceSpecifiers node which is in the Root.plist editor pane.

 

The node, PreferenceSpecifiers, is an array. This array node is designed to hold a set of dictionary nodes. Each of node represents a single preference that the user can enter or a single child view that the user can drill down into. Though Xcode gave us 4 nodes, we do not need all of them. So, delete items from 1 to 3.

Expand Item 0, and notice that the button changes to a different icon. This icon indicates that clicking that button now will add a child node.

 

The first row under Item 0 has a key of Type, and every property list node in the PreferenceSpecifiers array must have an entry with this key. Let’s take a look at the Type field under Item 0. The value of this Type field, Group Specifier, is used to indicate that this item represents the start of a new group. Each item that follows will be part of this group, until the next item with a Type of Group Specifier. The only other entry in Item 0 has a key of Title, and this is used to set an optional header just above the group that’s being started.
Let’s make some changes here.

Step 8 : Now Adding the TextField into seetings

Now it’s time to add the first actual preference field. Let’s add a second item in this array. Click the button to add a child after selecting the PreferenceSpecifiers. The new row will be inserted at the beginning of the list, which is not what we want. We want to add a row at the end of the array. To do that, click the disclosure triangle to the left of item 0 to close it, and sibling row after the current row.

 
Click the add child node button to add our first entry to this dictionary. A new row will come up and default to a String type, which is what we want. The new row’s key value will default to New item. Change it to Type.

 

TextField is the type of a specific preference field. When you see Type in the Key column, we’re defining the type of field that will be used to edit the preference.

Click the button with the plus icon to the right of the Type row to add another item to our dictionary. The next row will specify the label that will be displayed next to the text field. Change the key from New item to Title. Press the tab key. Set the Value to Username. Then press the plus button at the end of the Title row to add yet another item to our dictionary.

Change the key to Key and username for Value. Add another item to our dictionary give AutocapitalizationType for a Key and None for a Value. For the last row, give AutocorrectionType and No.

Now Run the Application and shows the settings of the simulator or the Devices.

 

Step 9 : Secure Text Field Setting

Let’s add the rest of the fields for our root settings view. The first one we’re going to add is a secure text field for the user’s password.

Another way of adding node. Copy Item 1 and Paste it at the same row 1. Then, we will have a new item, Item 2. Set the Title to Password and the Key to password.

Add one more child to the new item below the Key item. Give the new item a Key of IsSecure, and change the Type to Boolean. Once we do that, the space where we normally type in a value will change to a checkbox. Click it to check the box. This tells the Settings application that this field needs to be a password field rather than just an ordinary text field.

Step 10 : Multi value Field

This type of field will automatically generate a row with a disclosure indicator. If we click it, it will take us down to another table where we can select one of the rows. Let’s collapse Item 2. Add Item 3. Change the Type to Dictionary. Then, expand Item 3.

Set Type for a key and Multi Value for a value. Add a second row with a key of Title and value of Protocol. For a third row, set a key of key and a value of protocol.

We will add two more children to Item 3. But they are going to be an Array type nodes, not String type nodes. One, called Titles, is going to hold a list of the values that the user can select from. The other, called Values, is going to hold a list of the values that actually get stored in the User Defaults. So, if the user selects the first item in the list, which corresponds to the first item in the Titles array, the Settings application will actually store the first value from the Values array. This pairing of Titles and Values lets us present user-friendly text to the user but actually store something else, like a number, a data, or a different string. Both of these arrays are required. If we want them both to be the same, we can create one array, copy it, paste it back in, and change the key so that we have two arrays with the same content but stored under different keys. We’ll do just that.

Add a new child to Item 3. Change its kew to Values and set its type to Array. Add 5 child nodes. All five nodes should be String type nodes and should contain the following values: HTTP, SMTP, NNTP, IMAP, and POP3 as in the picture below.

Collapse Values. Copy and Paste will give us Values -2 and change the name of the “Value – 2 ” to “Titles”

 

Now Run the Application and shows the settings of the simulator or the Devices.

 

 

Step 11 : Toggle Switch Setting

The next item we need to get from the user is a Boolean value that indicates whether the warp engines are turned on. To capture a Boolean value in our preferences, we will tell the Settings application to use a UISwitch by adding another item to our PreferenceSpecifiers array with a type of PSToggleSwitchSpecifier.

Create Item 4. Change its type to Dictionary, and then expand it.
Add a child row, give it a kew of Type and a value of PSToggleSwitchSpecifier. Add another child with a key of Title and a value of Warp Drive. Then, add a third child with a key of Key and a value of warp.

By default, a toggle switch will cause a Boolean YES or NO to get saved into the user defaults. If we would prefer to assign a different value to the on and off positions, we can to that by specifying the optional keys TrueValue and FalseValue. We can assign strings, dates or numbers to either the on position(TrueValue) or the off position(FalseValue) so that the Settings application will store the string we specify instead of just storing YES or NO. Let’s set the on position to save the string Engaged and the off position to store Disabled.

We do this by adding two more children to Item 4, one with a key of TrueValue and a value of Engages, and the second one with a key of FalseValue and a value of Disabled.

Still, we have one more required item in this dictionary. That is the default value. If we had not supplied the option FalseValue and TrueValue items, we would create a new row with a kew of DefaultValue and change the type from String to Boolean. However, because we did add those two items, the value we put in DefaultValue has to match either the value passed in TrueValue or the one passed in FalseValue.

So, let’s make our warp engines on by default, so create one last child to Item 4, give it a key of DefaultValue and a value of Engaged. Note that the string “Engaged” is what will be stored in the user default, not what will appear on the screen.

 

 

Run your application

 

Step 12 : Slider Setting

In the Settings application, a slider can have a small image at each end, but it can’t have a label. Let’s put the slider in its own group with a header so that the user will know what the slide does.

Copy Item 0 and paste on Item 4. Since Item 0 was a group specifier, the item we just pasted in as the new Item 5 is also a group specifier and will tell the Settings application to start a new group at this location.

Change the value of Title under Item 5 to Warp Factor. Then, add a new row as a sibling of Item 6. Change the Type of the new row, Item 6, from String to Dictionary and expand the row. Add a child row, and give it a key of Type and a value of PSSliderSpecifier. This indicates to the Settings application that it should use a UISlider to get this information from the user. Add another child with a key of Key and a value of warpFactor so that the Settings application knows what key to use when storing this value.

We will allow the user to enter a value from one to ten, and we’ll set the default to warp t. Sliders need to have a minimum value, a maximum value, and a starting value, and all of these need to be stored as numbers, not strings, in your property list. To do this, add three more child rows to Item 6, setting the Type of all three rows from String to Number. Give the first one a key of DefaultValue and a value of 5. Give the second one a key of MinimumValue and a value of 1, and give the third one a key of MaximumValue and a value of 10.

Save and run the Application

 

Step 13 : Child Setting View

We will add another preference specifier to tell the Settings application that we want it to display a child settings view. This specifier will present a row with a disclosure indicator that will take the user down to a whole new view fill of preferences when tapped. Because we don’t want this new preference to be grouped with the slider, we will copy the group specifier Item 0 and paste it at the end of the PreferenceSpecifiers array to create a new group for our child settings view. After expanding Item 7, change General Info to Additional Info.

Collapse Item 7, and make a sibling, Item 8. This will be our actual child view. Change the new row’s type from String to Dictionary. Then add a child, and give it a key of Type and a value of PSChildPaneSpecifier. Add another child row with a key of Title and a value of More Settings.

Here i use more which is the name of the another .plist file which .plist entry below.

One more row, which will tell the Settings application which property list to load for the More Settings view. So, add another child row and give it a key of File and a value of More. he file extension .plist is assumed and must not be included, or the Settings application won’t find the property list file.

We’re adding a child view to our main preference view. That settings in that child view are specified in the More.plist file. We need to copy More.plist into the settings bundle. We can’t add new files to the bundle in Xcode, and the Property List Editor’s Save dialog will not let us save into a bundle. So, we have to create a new property list, save it somewhere else, and then drag it into the Settings.bundle window using th Finder.

Save and run the Application

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *



*