Contents

ControlCenter

An object you use to access configuration information for controls and reload them.

Declaration

class ControlCenter

Overview

ControlCenter provides information about user-configured controls, such as their push information.

For additional information about offering controls that allow people to perform app actions; – for example, in Control Center on iPhone – refer to Creating controls to perform actions across the system. For more information about offering user-configured controls, refer to Add configuration to a control.

Access configured control information

To get a list of user-configured controls, use currentControls(). This property provides an array of ControlInfo objects containing the following information:

struct ControlInfo {
    public let kind: String
    public func configurationIntent<Intent: ControlConfigurationIntent>(of intentType: Intent.Type = Intent.self) -> Intent?
    public var pushInfo: ControlPushInfo?
}

The kind string matches the parameter you use when defining the control type. If your control uses a AppIntentControlConfiguration, the configurationIntent(of:) function provides the custom intent containing the user-customized values for each individual control. If your control receives push notification updates, pushInfo returns the push token you use to update it.

For more information about updating controls with WidgetKit push notifications, refer to Updating controls locally and remotely.

Request a reload of your controls

Changes in your app’s state may affect a control’s state. When this happens, you can tell ControlCenter to reload the template for either a specific kind of control or all controls. For example, someone might press a button in your app that changes state shared by a control. The app should reload that control for its display to reflect the new state.

You don’t need to reload controls in response to push notifications. The system reloads any controls that receive push notification updates on your behalf.

If you only need to reload a certain kind of control, you can request a reload for only that kind. For example, in response to the user toggling an appliance on or off, you could request a reload for only the appliance widgets:

ControlCenter.shared.reloadControls(ofKind: "com.myhome.appliancepower")

To request a reload for all of your controls:

ControlCenter.shared.reloadAllControls()

Topics

Instance Methods

Type Properties

See Also

Setup and configuration