I developed a single page app and a keyboard extension, and I want to send data from my keyboard extensions to my app. I have created an App Group and added it to both targets; the entitlement files are located under each target folder.
In the simulator, it works fine; but when I run it on my device, I cannot access data saved by the extension. Interestingly, I can access data on the extension, saved by the app.
When running my app and extension on the simulator, I get no warnings/errors, but when running on the device I get the following warning when writing data to the shared container:
2020-11-05 12:19:14.542150-0600 TestKeyboard[2887:46080] [User Defaults] Couldn't write values for keys (
"test_key2"
) in CFPrefsPlistSource<0x282052000> (Domain: DOMAIN_NAME, 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
In other forums, I saw that sometimes these messages appear but the values are still stored in the shared container, but that's not my case.
Not sure if this information helps, but I do not have an apple developer paid subscription.
I am running this code on an iPhone 8 Plus, iOS 13.6. XCode version 12.1.
Thank you.
As pointed out by @EmilioPelaez, the keyboard extension needs full access so that App Groups can work. It worked in the simulator, because keyboard extensions in the simulators are always granted full access.
To grant full access to a keyboard extension, set RequestsFullAccess to True, in the NSExtension -> NSExtensionAttributes extension's plist.