Access iOS App / WatchOS App data from WidgetKit Complication (WatchOS 9)

1k Views Asked by At

I have an app inlcuding an Apple Watch app and a WidgetKit (iOS 16) extension.

The iOS app sends data via WatchConnectivity to the Apple Watch app and displays it there. Also it provides data to a WidgetKit (iOS 16 - Lockscreen) extension using GroupUserDefaults. All of this works without any issues ✅.

My issue:

I'm now trying to supply data to a WidgetKit complication extension (WatchOS 9). I expected to be able to either access the previously written UserDefaults of the Apple Watch app or the shared GroupUserDefaults. But I can't access any of it's data. I also checked the documentation, but I can't find any methods explicitely designed to share data to the complications. ClockKit methods will not be available for WidgetKit complications (https://developer.apple.com/documentation/widgetkit/converting-a-clockkit-app).

Did anybody manage to share data to a WidgetKit complication without requesting a Server API like in the Apple example? (https://developer.apple.com/documentation/widgetkit/adding_widgets_to_the_lock_screen_and_watch_faces)

1

There are 1 best solutions below

7
On

So I can answer my own question:

App Group shared UserDefaults are available only on the device itself it seems. Therefore it's necessary to enable the App Group capability on the WidgetKit extension of the Watch app as well as on the Apple Watch app. The Watch App can then write the data recieved through WatchConnectivity to the App Group shared UserDefaults from where the WidgetKit extension can access it.

So if you encounter any issues, check the capabilites of both targets and also profiles and identifiers, if you manage certificates manually/fastlane.