I have created a simple app in Swift that contains a WebViewControl
. Thanks to a SettingsBundle
the user is able to specify a URL that is then opened in the WebView. Root.plist
looks like this:
<?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>PSTextFieldSpecifier</string>
<key>Title</key>
<string>URL</string>
<key>Key</key>
<string>app_url</string>
<key>DefaultValue</key>
<string>https://myurl.com</string>
<key>IsSecure</key>
<false/>
<key>KeyboardType</key>
<string>URL</string>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
</dict>
</array>
</dict>
</plist>
This works fine. However when trying to retrieve the app_url
in Swift I am running in a problem.
override func viewDidLoad() {
super.viewDidLoad()
registerSettingsBundle()
print("retrieving key")
if let appUrl = UserDefaults.standard.string(forKey: "app_url") {
print("got it " + appUrl)
}
}
func registerSettingsBundle(){
let appDefaults = [String:AnyObject]()
UserDefaults.standard.register(defaults: appDefaults)
}
This prints retrieving key
to the console, but never the second print statement.
It was working a while ago, but a recent update broke it. What am I doing wrong? Has the API changed somehow? I read the documentation from Apple on UserDefaults, but it hasn't helped me so far.
Edit regarding marked as duplicate
: It is crucial that the user is able to change app_url
using the Settings app in iOS. Just reading the plist file as a dict is not sufficient. Please excuse me, this is the first time I am experimenting with iOS apps.