2

I want to read UserDefaults when a user changes the configuration for a widget, so I created an app group and added the capabilty to my main app, the widget extension and the Intent extension.

I can read and write fine between my app and the widget extension, however the UserDefaults always return nil in IntentHandler.swift, what could cause this?

// called from TimelineProvider
func example() -> String {

let sharedDefaults = UserDefaults.init(suiteName: "group.myname")
  let value = sharedDefaults!.value(forKey: "myKey") as! String
// value == “Hi this works!”
}

But when I call example() from my IntentHandler value is nil. (It crashes)

pawello2222
  • 46,897
  • 22
  • 145
  • 209
Kipnoedels
  • 1,118
  • 7
  • 22

1 Answers1

5

As EmilioPelaez commented, double check the capabilities (even if you've already done so, I didn't notice this either). My app group was only enabled for release mode, not debug. Should have noticed this sooner...

Kipnoedels
  • 1,118
  • 7
  • 22