I’m trying to share data between ShieldConfigurationExtension and ShieldActionExtension to update the shield after performing an action.
I created an app group, enabled it for both extensions and my main app. But when I’m writing data in ShieldConfigurationExtension I cannot get it in the ShieldActionExtension.
Here is how I do it:
// In ShieldConfigurationExtension
let sharedDefaults = UserDefaults(suiteName: "your.app.group.identifier")
sharedDefaults?.set("yourData", forKey: "sharedKey")
sharedDefaults?.synchronize()
// In ShieldActionExtension
let sharedDefaults = UserDefaults(suiteName: "your.app.group.identifier")
if let sharedData = sharedDefaults?.string(forKey: "sharedKey") {
// Use sharedData in ShieldActionExtension
}
What is interesting writing data from my main app works and I can read it in both extensions.
I’ve tried to recreate the app group, but that didn’t helped.




