【问题标题】:root.plist changes not visible on iphoneroot.plist 更改在 iPhone 上不可见
【发布时间】:2010-08-01 02:05:08
【问题描述】:

当我将新条目添加到我的设置捆绑 root.plist 文件、构建并运行应用程序时,新设置在应用程序中不可见。我当然为新条目使用了唯一键。

在我的 xcode 项目的 root.plist 文件中,该文件显示了更改,但是当我通过管理器从 iphone 获取当前文件时,更改不存在。

我使用的是 iOS 4.0.1。

BR, 马丁

【问题讨论】:

    标签: iphone ios4 nsuserdefaults


    【解决方案1】:

    删除并重新安装该应用。当应用程序已存在于设备上时,可能无法安装更新的资源。

    【讨论】:

    • 好的,你能澄清一下“新设置在应用程序中不可见”的意思吗? root.plist 设置文件不会影响您的应用。它会影响“设置”应用。您是否希望它在您的应用程序中为 NSUserDefaults 定义默认值?你有责任自己注册+[NSUserDefaults registerDefaults:]
    • 我没有在应用程序中定义任何设置。我所做的一切是,我已经在根 .plist 中定义了我的设置(包括默认值)。我想在应用程序中阅读它们。我可以读取文件中最初的所有设置。但是我使用属性列表编辑器添加的新条目无法通过 NSUserDefaults 读取。我总是得到一个 IllegalArgumgentException。我将发布 root.plist 作为我问题的答案。
    • IllegalArgumentException?你正在做一些绝对错误的事情。如果缺少值,NSUserDefaults 不会触发异常。而且它不会读取 root.plist,正如我已经说过的 - 该文件 only 影响 Settings.app.
    【解决方案2】:

    Root.pList

    <?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>StringsTable</key>
        <string>Root</string>
        <key>PreferenceSpecifiers</key>
        <array>
            <dict>
                <key>Type</key>
                <string>PSGroupSpecifier</string>
                <key>Title</key>
                <string>iParkschein Einstellungen</string>
            </dict>
            <dict>
                <key>Type</key>
                <string>PSTextFieldSpecifier</string>
                <key>Title</key>
                <string>Kennzeichen</string>
                <key>Key</key>
                <string>kennzeichen_preference</string>
                <key>DefaultValue</key>
                <string></string>
                <key>IsSecure</key>
                <false/>
                <key>KeyboardType</key>
                <string>Alphabet</string>
                <key>AutocapitalizationType</key>
                <string>None</string>
                <key>AutocorrectionType</key>
                <string>No</string>
            </dict>
            <dict>
                <key>Type</key>
                <string>PSTextFieldSpecifier</string>
                <key>Title</key>
                <string>Stadt</string>
                <key>Key</key>
                <string>stadt_preference</string>
                <key>DefaultValue</key>
                <string>Wien</string>
                <key>IsSecure</key>
                <false/>
                <key>KeyboardType</key>
                <string>Alphabet</string>
                <key>AutocapitalizationType</key>
                <string>None</string>
                <key>AutocorrectionType</key>
                <string>No</string>
            </dict>
            <dict>
                <key>Type</key>
                <string>PSToggleSwitchSpecifier</string>
                <key>Title</key>
                <string>Firmenrechnung</string>
                <key>Key</key>
                <string>firmenrechnung_preference</string>
                <key>DefaultValue</key>
                <true/>
            </dict>
            <dict>
                <key>Type</key>
                <string>PSTextFieldSpecifier</string>
                <key>Title</key>
                <string>Kennzeichen</string>
                <key>Key</key>
                <string>servicenummer_preference</string>
                <key>DefaultValue</key>
                <string></string>
                <key>IsSecure</key>
                <false/>
                <key>KeyboardType</key>
                <string>Alphabet</string>
                <key>AutocapitalizationType</key>
                <string>None</string>
                <key>AutocorrectionType</key>
                <string>No</string>
            </dict>
        </array>
    </dict>
    </plist>
    

    如果我从 userdefaults 读取密钥并将它们写入控制台,我会得到除 servicenummer_preference 之外的任何密钥

    BR, 马丁

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 2020-10-20
      • 2012-12-22
      • 1970-01-01
      相关资源
      最近更新 更多