Learn how to create a tab on the 'Settings' application for your own app's defaults and settings. iPhone 3 SDK on Snow Leopard.
Based on Chapter 10 ‘Application Settings and User Defaults’ Apress Beginning iPhone 3 Development: Exploring the iPhone SDK by Dave Mark and Jeff LaMarch
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
iPhone Dev: Application Settings and Defaults
1. Application Settings
and User Defaults
- Parimal Satyal (realityequation.net)
October 28, 2009
Based on Chapter 10 ‘Application Settings and User Defaults’
Apress Beginning iPhone 3 Development: Exploring the iPhone SDK
by Dave Mark and Jeff LaMarch
2. Prefs
Most Mac apps have ‘Preferences’
Persistent Data/Settings
Settings app on iPhone OS
UI is built for you, uses plist
3. Settings
Apps can have own
tab in the Settings app
When in-app, when in
Settings app?
‘Backdoor’ prefs that
don’t need changing
Else, users must quit
7. Settings Bundle
‘Settings Bundle’ to provide the data
Each bundle must have Root.plist
Additional views through
additional plists as child views
in Root.plist
9. Root.plist Format
Root node is always a dictionary
(so must have key and value)
Children nodes can be:
Dictionaries • capable of containing other data
Arrays • capable of containing other data
Boolean
Data
Number
String
StringsTable for localization; ignore
14. Adding Stuff
and Grouping
Notice change in icons when expanded
PSGroupSpecifier signals new group
The contents of Root.plist determine
the UI and structure of Settings app
15. Other Inputs
Secure Text Field (isSecure key)
Multivalue field: PSMultiValueSpecifier
Array as child, with separate
Key list and Value list
Toggle Switch: PSToggleSwitchSpecifier
Slider: PSSliderSpecifier
20. Magic of Root.plist
Open Root.plist
Spend some time playing around and
seeing what changes what
Add another control:
A Toggle, a Slider or just a Text Field
21. Getting Settings data
Easy, using the NSUserDefaults class
NSUserDefaults *defaults =
[NSUserDefaults standardUserDefaults];
defaultsbecomes a dictionary, so we can
do stuff like:
(NSString *) objectForKey:
(NSDate *) objectForKey:
(int) intForKey:
(BOOL) boolForKey:
23. MainViewController
Explore the .h and .m files
Take a look at these methods:
refreshFields:
flipSideViewControllerDidFinish:
viewDidAppear:
Declaring constants, creating a method
Property-ize and synthesize elements
Map them using NSUserDefaults class &
objectForKey: method