WidgetCenter
An object that contains a list of user-configured widgets and is used for reloading widget timelines.
Declaration
class WidgetCenterMentioned in
Overview
WidgetCenter provides information about user-configured widgets, such as their family. For widgets that use IntentConfiguration, you can retrieve the user-edited values.
Getting Configured Widget Information
To get a list of user-configured widgets, use getCurrentConfigurations(_:). This property provides an array of WidgetInfo objects containing the following information:
struct WidgetInfo {
public let configuration: INIntent?
public let family: WidgetFamily
public let kind: String
}The kind string matches the parameter you use when creating the widget’s StaticConfiguration or IntentConfiguration. The family property matches one of the options specified in the supportedFamilies(_:) property of the widget’s configuration. If your widget is based on IntentConfiguration, the configuration property provides the custom intent containing the user-customized values for each individual widget.
Requesting a Reload of Your Widget’s Timeline
Changes in your app’s state may affect a widget’s timeline. When this happens, you can tell WidgetKit to reload the timeline for either a specific kind of widget or all widgets. For example, your app might register for push notifications based on the widgets the user has configured. When your app receives a push notification that changes the state for one or more of your widgets, requesting a reload of their timelines updates their display.
If you only need to reload a certain kind of widget, you can request a reload for only that kind. For example, in response to a push notification about a change in a game’s status, you could request a reload for only the game status widgets:
WidgetCenter.shared.reloadTimelines(ofKind: "com.mygame.gamestatus")To request a reload for all of your widgets:
WidgetCenter.shared.reloadAllTimelines()