Hello everyone,
I have problems using SharedUserDefaults with a keyboard-extension.
I could not reproduce the error-message in the simulator, it only appears on real devices.
I created
Target Membership both my main-app and keyboard-extension.
In the app I load
and save a textfield to it.
I can also load this here, everything works.
Inside my extension I load it with
This also works in the simulator, but not on my real device.
It always takes the first value I have saved inside the app the first time:
The only hint I have is when saving a value inside the extension I get a message
I am running iOS 14.2.1, I am quite sure that this was working on iOS 13, but unfortunately I have no second device with iOS 13 to test now.
I have problems using SharedUserDefaults with a keyboard-extension.
I could not reproduce the error-message in the simulator, it only appears on real devices.
I created
Code Block language struct SharedUserDefaults { static let suiteName = "group.***.MyGroup" struct Keys { static let addon = "addon" static let lastcomment = "lastcomment" } }
Target Membership both my main-app and keyboard-extension.
In the app I load
Code Block language let sharedUserDefaults = UserDefaults(suiteName: SharedUserDefaults.suiteName)
and save a textfield to it.
Code Block language if let var_textfield = textfield_addon.text { sharedUserDefaults?.set(var_textfield, forKey: SharedUserDefaults.Keys.addon) }
I can also load this here, everything works.
Inside my extension I load it with
Code Block language guard let var_addon = sharedUserDefaults?.string(forKey: SharedUserDefaults.Keys.addon) else {return ""} return var_addon
This also works in the simulator, but not on my real device.
It always takes the first value I have saved inside the app the first time:
app > save "1" > extension load > "1"
app > save "2" > extension load > "1"
The only hint I have is when saving a value inside the extension I get a message
Unfortunately I was not able to solve it with this message, as also the online-tutorials do it like my current code.[User Defaults] Couldn't write values for keys (lastcomment)in CFPrefsPlistSource<0x2817f5b00> (Domain: group.***.MyGroup, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
I am running iOS 14.2.1, I am quite sure that this was working on iOS 13, but unfortunately I have no second device with iOS 13 to test now.