[英]How to work with Settings.bundle
I'm developing an iOS app with latest SDK. 我正在使用最新的SDK开发iOS应用。
I have created a Settings.bundle
with a Root.plist
and another four .plist
and every setting on these files have each default value. 我用Root.plist
和另外四个.plist
创建了Settings.bundle
,这些文件上的每个设置都有每个默认值。
This is the first time I work with Settings.bundle
and I'm lost. 这是我第一次使用Settings.bundle
,我迷路了。 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. 我发现了这个问题 ,他们说我每次运行应用程序时都必须阅读Settings.bundle
默认值,但我不明白为什么。
I think I have to continue using NSUserDefaults
here to read settings values. 我想我必须在这里继续使用NSUserDefaults
来读取设置值。
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;
}
The identifier
of any preference item in the Settings.bundle plist can be accessed with NSUserDefaults
. 可以使用NSUserDefaults
访问Settings.bundle plist中任何首选项的identifier
。 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). 例如,如果您有一个带有名为allowDiagnostics
的标识符的首选项,则可以使用[NSUserDefaults standardUserDefaults] boolForKey:@"allowDiagnostics"]
访问该项目的值(假设它是BOOL
项)。
You can use the NSUserDefaultsDidChangeNotification
to get notified of any changes to your preferences. 您可以使用NSUserDefaultsDidChangeNotification
来通知您的首选项更改。
The same way you read them. 您阅读它们的方式相同。 To continue the example of 1, [NSUserDefaults standardUserDefaults] setBool:YES forKey:@"allowDiagnostics"]
. 继续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. 但是请注意,允许用户从多个位置(Settings.bundle和应用程序中的某个位置)更改选项可能会使用户感到困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.