Friday 2 December 2011

IPhone Software Development Kit , Application Preferences


An IPhone Application can be configured via the Settings menu, this tutorial illustrates how you can make a settings view for your app and then read the selected settings from your application.

Contents


Step 1: Create a Sample Application
·         I have used an application similar to the one created in the lesson obtainable here (IPhone SDK Hello World).

Step 2: Create a Settings Bundle

Create a new File Command + N and then select Settings from the side menu and Settings  Bundle.
This is in fact a graphical representation of an XML file which defines the settings and how they are displayed. (You can see the xml code by right clicking the file and selecting Open as Plain Text. The file must be named Settings.bunch to work fittingly. This will create two new files Root.strings and Root. plist. Open the Root.plist file and you should see the subsequent screen register some sample settings.

Step 3: Define Settings Schema

The Root element has three child basics (1) Title; which defines the title of this settings view and is set to the name of the request. (2) StringTable; which is not covered in this tutorial. (3) PreferenceSpecifiers which contains all the settings we wish to obtain from the user. PreferenceSpecifiers has type Array and has a child element of type glossary for each setting: Item 1, item2 and so forth. We can add items by selecting PreferenceSpecifiers and clicking the Grey button at the end of the row.

Each setting has plentiful properties of type string including the common required properties; Title and Type (Note all strings are case sensitive). There are seven probable controls which can be selected using the Type material goods. The title defines the label displayed beside the control used to modify the setting and type defines the type of control used.

PSGroupSpecifier

This is the simplest control and has only the two properties defined described beyond. It is used as a separator to break-up groups of similar settings. It cannot believe any input from the user.

PSTitleValueSpecifier

This displays a "Read Only" setting it cannot accept input from the user but can be used to present settings changed somewhere else.

Key:

This is a run property which can be set to any text, the text is used as a key to map to the value that a user will enter into the control.  

DefaultValue:

Another String chattels which can store any text, this defines the Text that will be displayed in the specifier.

PSTextFieldSpecifier:

The next category of control is the TextField, it has some bonus properties which are listed below.

Key:

This is a String chattels which can be set to any text, the text is used as a key to map to the rate that a user will enter into the text field.  
DefaultValue:                                                                                                                                                              Another String property which can store any text this defines the initial Text that will be entered into the TextField when it is first loaded.

IsSecure:

This is a boolean property which defines if the charecters of the text field will be hidden, set to enabled for password fields.

KeyboardType:

A filament possessions which can have one of the subsequent values: Alphabet, NumbersAndPunctuati on, NumberPad, URL, EmailAddress. This property specifies which type of keyboard to exhibit when text field is favorite.

AutocapitalizationType:

A thread property which can have one of the following values: None, Sentences, Words, AllCharacters

AutoCorrectionType:

A filament property which can have one of the subsequent values: Default, No, Yes

PSSliderSpecifier:

This displays a slider on a bar which allows the user to select a number in a specified range. In totaling to the standard Title and Type specifiers the Slider has the follow properties.

Key:

This is a series possessions which can be set to any text, the text is used as a key to map to the value that a user will enter into the control.  

MinimumValue:

A property storing a mathematical value which corresponds to the slider being on the missing end of the bar.

MaximumValue :

A home storing a numerical value which corresponds to the slider being on the right end of the bar.

DefaultValue:

 A geometric  goods which defines the original location of the slider. 

PSToggleSwitchSpecifier


Displays a toggle switch which can be either
On or Off.

Key:

This is a series property which can be set to any text, the text is worn as a key to map to the rate that a user will enter into the control. 

TrueValue:

A boolean property which defines the value of the control of the toggle pin is in the On pose.
FalseValue:                                                                                                                                                                     A boolean property which defines the value of the control of the toggle button is in the Off position.

DefaultValue:

A boolean property which defines the location of the Toggle switch the first time it is loaded.

PSMultiValueSpecifier:

Displays a list in a following view and allows the user to select one factor from the list.

Key:

This is a String property which can be set to any text, the text is used as a key to map to the cost that a user will penetrate into the control. 

Values:

A goods of type Array which provisions sub-elements of type String, each element provides a a pos sible value for the manage to take. 

Titles:

A property of type array which supplies sub-elements of type String, each element provides a textual representation of one of the values specified in the earlier property. For example if the first factor of the values collection is "01" and the first element of the titles array is "January" then the user is shown January but if January is selected the value stored for the control is 01.  

DefaultValue:

Another String property that defines the initial value of the control, should be one of the basics of the Values list.

PSChildPaneSpecifier  

Key:

This is a series property which can be set to any text, the text is used as a key to map to the charge that a user will enter into the control. 

File:

The name of an extra plist file without the annex.
Step 4: Retrieving Values of Settings

You can recover the value of a setting by using the control given less; Replace the hilighted text with the name of the location you want to get the value of. 

NSString* settingValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"<Setting Key>"]

Step 5: Loading a Child Pane

The final of the Seven control allows you to add a sub view. The method to do so is to add a new file Command + N and select Other from the menu on the right Property List from the list of fle types.

Create a child prefernces schema closely as you created the original scheme.
No in the original plan add a PSChildPaneSpecifier and add a File item to the specifier with the file name of the child view (less the addition).

Technically this should be sufficient but as you will see if you run your code now the child view will not load. To load your child view the child plist file has to be within the settings collection but I can't find a way of doing this from within XCode (after half an our of random tinkering). So just open a workstation and move the file into the bundle yourself. To do this browse to the index containing your xcode project, and find child.plist file (or suchlike you named it). Use mv child.plist Settings.bundle/child.plist to move your file and then click Build and Go in XCode.

If there is some way of stirring files into the collection through XCode that you know of please leave a coment and I will update this file.

Concluding Note

This article is a bit raw please leave comment in case everything is not clear, you have some suggestions or if you spot any mistakes.
Appendix A: NSLogs

To see the NSLog output generated by clicking the "Load Preferences" button in the sample code click the highlighted switch in shown in the figure. It will open the log output window.



0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Powerade Coupons