Reputation: 45911
I'm developing an iOS app with latest SDK.
I have created a Settings.bundle
with a Root.plist
and another four .plist
and every setting on these files have each default value.
This is the first time I work with Settings.bundle
and I'm lost. I have found this question where they said that I have to read Settings.bundle
defaults values every time I run the application and I don't understand why.
I think I have to continue using NSUserDefaults
here to read settings values.
I have these questions:
By the way, now I have this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Set the application defaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults boolForKey:@"firstRun"])
{
NSDictionary *appDefaults = [PreferenceDefaultValues dictionary];
[defaults registerDefaults:appDefaults];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstRun"];
[defaults synchronize];
}
return YES;
}
Upvotes: 0
Views: 1284
Reputation: 16946
The identifier
of any preference item in the Settings.bundle plist can be accessed with NSUserDefaults
. For example, if you have a preference item with an identifier named allowDiagnostics
, then you can access the value for that item with [NSUserDefaults standardUserDefaults] boolForKey:@"allowDiagnostics"]
(assuming that it was a BOOL
item).
You can use the NSUserDefaultsDidChangeNotification
to get notified of any changes to your preferences.
The same way you read them. To continue the example of 1, [NSUserDefaults standardUserDefaults] setBool:YES forKey:@"allowDiagnostics"]
. Note though, that allowing the user to change options from multiple places (Settings.bundle and somewhere in your app), can be confusing to the user.
Upvotes: 3