简体   繁体   English

如何使用Settings.bundle

[英]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: 我有以下问题:

  1. How can I read the values set on these settings using Setting app? 如何使用“设置”应用读取在这些设置上设置的值?
  2. How can I know if the user changes one or more of these values? 我怎么知道用户是否更改了一个或多个这些值? The user makes the app to goes background, open Setting app and change something. 用户使应用程序进入后台,打开“设置应用程序”并进行更改。 How can I know that programmatically? 我如何以编程方式知道这一点?
  3. How can I save any modification (a change in a setting value) and see that change on Settings app? 如何保存任何修改(设置值的更改)并在“设置”应用程序上看到该更改?

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;
}
  1. 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项)。

  2. You can use the NSUserDefaultsDidChangeNotification to get notified of any changes to your preferences. 您可以使用NSUserDefaultsDidChangeNotification来通知您的首选项更改。

  3. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM