This is very strange. I must be doing something fundamentally wrong.
My iPhone app has some preferences, with defaults stored in Settings.bundle/Root.plist. Looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Title</key>
<string>iDSControl</string>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>D3 IP Address</string>
<key>Key</key>
<string>ip_address</string>
<key>DefaultValue</key>
<string>192.168.1.250</string>
<key>IsSecure</key>
<false/>
<key>KeyboardType</key>
<string>NumbersAndPunctuation</string>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
</dict>
</array>
</dict>
</plist>
The code to read the preference is:
Code:
#define kIPAddressKey @"ip_address"
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSString *ipAddress = [[NSUserDefaults standardUserDefaults] stringForKey:kIPAddressKey];
// do something with ipAddress here....
[window makeKeyAndVisible];
}
When I first install this on the iPhone, the application crashes because ipAddress is NULL. If I switch to the Settings app and look at the page for this app, the default value from the Settings.bundle is there. When I switch back to the app, it runs fine. So apparently my app isn't getting the defaults until after Settings is run once. Any ideas on how to force it to update? I guess I could look for the null value, and throw an alert, but that's not very friendly. At best, it should use the default I defined. At worst, I'd like to know how to switch over to the Settings app.
Thanks!
joe