how do I create a new control widget

Asked on 2024-07-30

1 search

To create a new control widget, you can follow the steps outlined in the session "Extend your app’s controls across the system" from WWDC 2024. Here is a summary of the process:

  1. Introduction to Controls:

    • Controls are a new type of widget in iOS 18, created using WidgetKit.
    • They provide quick access to actions from your app and can be placed in system spaces like Control Center, the lock screen, and the action button.
    • There are two types of controls: buttons (perform discrete actions) and toggles (change a piece of boolean state).
  2. Building a Control:

    • Start by adding a control entry into your existing widget bundle.
    • Define the control in the widget extension by conforming to the ControlWidget protocol.
    • Provide the necessary information for the control, such as a unique identifier, title, state, action to perform, and symbol image.
    • Use an app intent to execute actions when the control is interacted with.
  3. Configuring the Control:

    • Begin with a static control configuration and add configurability later if needed.
    • For configurable controls, use an AppIntentControlConfiguration to manage the configuration.
    • Customize the display name and add a description for the control.
  4. Refining the Control:

    • Tailor the control style to the action it performs.
    • Ensure the control features distinctive symbols and provides additional content as needed.

For a detailed walkthrough, you can refer to the session Extend your app’s controls across the system (03:11).

Relevant Sessions

  1. Extend your app’s controls across the system
  2. Bring your app’s core features to users with App Intents

These sessions provide comprehensive guidance on creating and configuring control widgets using WidgetKit and App Intents.