I have a WidgetBundle to show multiple Widgets for my app.
Recently I migrated over ClockKit complications to use WidgetKit.
Some of my Complications and now Widgets should only show up in the widgets list for a user if certain criteria is met, this criteria is stored in the main app and can change at runtime.
For Complications in ClockKit this was possible by using CLKComplicationServer.reloadComplicationDescriptor during runtime and returning the available descriptors based on the criteria. I've been looking for a similar method within WidgetKit but I can't seem to find one.
Is it possible to reload the widget list during runtime similar to how it was possible in ClockKit with CLKComplicationServer.reloadComplicationDescriptor.
WidgetKitdoesn't currently provide a direct way to reload the widget list during runtime.However, there are a couple of workarounds you can use to achieve a similar effect:
Trigger a background update: You can schedule a background update for your app using the
BackgroundTasksframework. This will cause your app to be launched in the background and given a chance to update its widget data. The widget list will then be refreshed the next time the user opens the widget gallery.Create a custom widget configuration provider: You can create a custom
WidgetConfigurationProvidersubclass that overrides thegetConfigurationForWidgetType()method. This method allows you to dynamically determine whether a widget should be included in the list based on your criteria. However, this approach requires you to manage the widget metadata and configurations yourself.Both of these workarounds have limitations compared to a direct API for reloading the widget list. The background update approach can be more reliable, but it requires you to schedule updates explicitly. The custom configuration provider approach gives you more control over the widget selection, but it adds more complexity to your app's architecture.
Hope this helps you!