-1

如果应用程序已通过 xcode 重新安装,则所有保留的设置都会被清除。如何避免这种行为?

更详细:已经安装了一个应用程序,然后我对设置(设置包)进行了更改并存储了它们。在我通过 xcode 重新安装了应用程序(我没有删除应用程序)并且我之前所做的所有设置都已清理之后。我想在安装应用程序后保留我的设置,或者可能有另一种方法在安装后保留应用程序的设置。

例子:

  1. 我创建了设置包(文件->新建->文件->资源->设置包)

  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>Server</string>
        </dict>
        <dict>
            <key>Type</key>
            <string>PSTextFieldSpecifier</string>
            <key>Title</key>
            <string>Address</string>
            <key>Key</key>
            <string>server_address_preference</string>
            <key>KeyboardType</key>
            <string>Alphabet</string>
            <key>IsSecure</key>
            <false/>
            <key>AutocapitalizationType</key>
            <string>None</string>
            <key>AutocorrectionType</key>
            <string>No</string>
        </dict>
    </array>
    

4

1 回答 1

0

保留应用程序使用的设置UserDefaults,它与 Android 开发中的概念相同SharedPreferences。因此,您可以在那里存储与用户相关的设置以及在更新(Xcode 重新安装)应用程序后应该保持不变的所有其他内容。

UserDefaults Apple 文档

使用示例。

设定值:

UserDefaults.standard.set(true, forKey: "someValue")

检索值:

let boolValue = UserDefaults.standard.bool(forKey: "someValue")
于 2018-03-12T09:57:02.007 回答