For the More Curious: The Settings Application

Every iOS device has a Settings application. Applications that register some or all of their preferences with Settings get an entry in this application where those preferences can be changed. However, most applications do not use Settings to store their preferences: why leave the application, find Settings, change a value, and then re-open the application when you could have your own built-in interface?

But, in case it’s something you want to do, here’s how. To register for an entry in Settings, you add a Settings.bundle to your application. This bundle contains a property list that has an entry for each preference you want to expose in the Settings application. (There is a template for this bundle when you create a new file.)

Each entry contains a key that is a string that matches the name of the preference keys you use with NSUserDefaults. Additionally, you set a preference specifier key with one of the pre-defined constants. These constants indicate the type of control that will appear for this preference in the Settings application. They are things like text fields, switches, and sliders. You also add a key for a default value. Some preference specifiers require you to add additional keys. For example, a slider preference will need a minimum and a maximum value.

If you choose to use a settings bundle, you must take care to respect the changes made in the Settings application when transitioning between application states. If your application is terminated and then the user changes a value in Settings, those changes will be written to disk, and the next time your application launches, it will get the correct values. However, most iOS applications are not terminated when the user presses the Home button. Thus, when your application returns from being suspended, you should check to see if any of the preferences were changed while it was suspended.

An application returning from the suspended state that has had preferences changed will be notified via the NSNotificationCenter. You can register for the NSUserDefaultsDidChangeNotification notification to be informed of these changes. (You typically register for this notification when the application first launches.)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.199.181