我可以动态修改设置包中的Root.plist吗? [英] Can i modify Root.plist in settings bundle dynamically?

查看:141
本文介绍了我可以动态修改设置包中的Root.plist吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个设置包..包含 root.plist
现在我有一个包含复选框的屏幕..
在按下复选框时,我想更改plist中PSToggleSwitchSpecifier的 DefaultValue 键的 BOOL 值。
因为它是在运行时完成的..我的问题是..可以在运行时更改文件,如果是的话......想一想如何做到这一点?

I have a settings bundle in my app.. containing root.plist now i have a screen which contains a checkbox.. on pressing the check box i want to change the BOOL value for DefaultValue key of PSToggleSwitchSpecifier in the plist. Since its being done at runtime.. my question is that .. can the file be changed at runtime and if yes.. give an idea how to do it??

这里是plist:

    <plist version="1.0">
<dict>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>DefaultValue</key>
            <string></string>
            <key>Key</key>
            <string>Username</string>
            <key>Title</key>
            <string>Username</string>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
        </dict>
        <dict>
            <key>DefaultValue</key>
            <string></string>
            <key>IsSecure</key>
            <true/>
            <key>Key</key>
            <string>Password</string>
            <key>Title</key>
            <string>Password</string>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
        </dict>
        <dict>
            <key>Type</key>
            <string>PSToggleSwitchSpecifier</string>    <-----toggleSwitch
            <key>Title</key>
            <string>Remember</string>
            <key>Key</key>
            <string>CheckBox</string>
            <key>DefaultValue</key>    <----- Default Value
            <false/>                   <---- want to change this value 
        </dict>
    </array>
    <key>Title</key>
    <string>Settings</string>
</dict>
</plist>

提前谢谢;)

推荐答案

因为设置包位于内部您的应用程序包中,所以无法在运行时更改它,仅在编译时。

Because the settings bundle resides inside your app's bundle, you cannot change it at runtime, only at compile-time.

但是,您可以使用 NSUserDefaults 在运行时设置值,设置应用程序将自动反映这一点。不过,它会被保存在其他地方。您可以像使用设置包一样阅读它,也可以通过 NSUserDefaults

请注意,您不应该直接从设置包中读取,因为它没有意义。您应始终使用 NSUserDefaults 获取和设置用户默认值。当用户在设置应用程序中进行更改时, NSUserDefaults 将自动反映此情况。它们将始终保持同步。

Note that you shouldn't read from the settings bundle directly, as it makes no sense. You should always fetch and set user defaults using NSUserDefaults. When the user makes a change in the settings application, NSUserDefaults will reflect this automatically. They will always be kept in sync.

这篇关于我可以动态修改设置包中的Root.plist吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆