Hi Apple team,
I'm experiencing a persistent issue with writing to UserDefaults from a widget extension on iOS. Here's the situation:
I've set up an App Group: group.test.blah
The main app has the correct entitlement and can read/write from UserDefaults(suiteName:) using this group successfully.
I can read the value written by the app from the widget (e.g., "testFromApp": "hiFromApp").
The widget extension has the same App Group enabled under Signing & Capabilities.
The provisioning profile reflects the App Group and the build installs successfully on a real device.
The suite name is correct and matches across both targets.
I’ve confirmed via FileManager.default.containerURL(...) that the app group container resolves properly.
When I try to write from the widget extension like this
let sharedDefaults = UserDefaults(suiteName: "group.test.blah")
sharedDefaults?.set("hiFromWidget", forKey: "testFromWidget")
...I get this error in the console:
Couldn't write values for keys (
testFromWidget
) in CFPrefsPlistSource<0x1140d2880> (Domain: group.test.blah, 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
Questions:
What could still cause the widget extension to lack write access to the app group container, even though it reads just fine?
Are there any internal sandboxing nuances or timing-related issues specific to Live Activity widgets that could explain this?
Is this a known limitation or platform issue?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
Extensions
Entitlements
ActivityKit
Files and Storage