WidgetKit complications won't update
Asked Answered
B

0

7

We are migrating ClockKit complications to WidgetKit in our watch app (watchOS 9+). The migration went smoothly, UI part works just fine. However, we've hit the wall with widgets not updating when requested by the watch app. I believe we are missing something very simple and fundamental, but couldn't find what exactly so far. Advice and tips would be very welcome! πŸ™‡β€β™‚οΈ

Our implementation details:

  • Whenever data is changed in the main app, the updated data is submitted to the watch app via WatchConnectivity framework using WCSession.default.transferCurrentComplicationUserInfo(_:). According to documentation, this method should be used to transfer complication-related data, since it will wake the watch app even if it is in the background or not opened at all.
  • Watch app receives updated data and stores it in UserDefaults shared with Watch Widget Extension hosting WidgetKit complications via App Group.
  • Watch app then request widget timeline reload via WidgetCenter.shared.reloadAllTimelines(). According to documentation, it reloads the timelines for all configured widgets belonging to the containing app, so it seems the appropriate way to reload WidgetKit complications.
  • Widget Timeline Provider class in Watch Widget Extension reads updated data from shared UserDefaults and uses it to provide the updated snapshot for widget views to render.

We believe our implementation logic is correct, but it doesn't work, for some reason. Widgets sometimes update when the watch app is opened, but not always. The most definitive way to force widgets to update is to switch to a different watch face, which confirms that the Widget Timeline Provider has access to properly updated data.

P.S. We are aware of the daily reload budget imposed on widgets, so we use widgets reload trigger sparingly. Anyway, according to documentation, reload budget is not effective when in DEBUG mode, but widgets won't reload even in DEBUG mode.

Minimum Reproducible Example app: https://github.com/SergejLogis/wkcomplications

Thank you!

Barmecide answered 9/8, 2023 at 8:25 Comment(9)
This really needs a Minimal, Reproducible Example (MRE). – Cassidy
@Cassidy yeah, makes sense! Added a link to the repo. Please check the readme for details. – Barmecide
The repo is not a Minimal, Reproducible Example (MRE). You should make an independent, minimal example and post the code here. The reasons for that are twofold: 1. many times when making the example, you answer your own question, 2. when someone searches for this question, they can se the context long after you have removed the repo from public view. – Cassidy
The issue we are having cannot be expressed with the "independent, minimal example" which can be posted here, I'm afraid. πŸ˜• The app in the repo I provided was created specifically to illustrate the communication approach we are using in our app and the issue we are having with WidgetKit complications. To reproduce the issue app requires 3 targets: iOS app, watchOS app, and watchOS Widget extension. And yes, I validated my own understanding of the problem when I was writing this app, it definitely helped! πŸ€“ – Barmecide
@Barmecide Hi. Have you found a solution ? – Doroteya
Unfortunately, I'm not. We have postponed migration to WidgeKit complications because of this issue. Our watch app still uses ClockKit for complications. πŸ€·β€β™‚οΈ – Barmecide
Please see my question on Apple Developer Forums, it has more responses and some useful insights: developer.apple.com/forums/thread/735352 – Barmecide
Does your app use a dual-target extension for the watch app? E.g. watch app + watch app extension? I had the same issue and the reload of complication was as buggy as it can get and the AppGroup took some time to sync with the latest data. I migrated my app to a single-target and it works flawlessly ever since! Here are steps descriped by Apple how to do the migration. – Coaly
I have migrated our watch app to the modern single-target version, but that didn't solve our issues. That was quite some time ago, though. I believe watchOS 10.1 was the last time I've checked πŸ€“ – Barmecide

© 2022 - 2024 β€” McMap. All rights reserved.