コントロールウィジェットの実装方法を紹介してください。

Generated on 8/7/2024

1 search

To implement control widgets in iOS 18, you can follow the steps outlined in the session Extend your app’s controls across the system. 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.
  2. Types of Controls:

    • There are two types of controls: buttons and toggles.
    • Buttons perform discrete actions, which can include launching your app.
    • Toggles change a piece of boolean state, like turning something on or off.
  3. Building a Control:

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

    • Controls can be static or configurable.
    • For configurable controls, use an app intent control configuration.
    • Define the configuration parameters and handle the control's actions accordingly.
  5. Refining Controls:

    • Customize the display name and description of your control.
    • Add status text if your control needs to convey additional information about its action or state.
    • Ensure your control syncs across all devices and reflects the correct state.

For a detailed walkthrough, you can refer to the following chapters in the session Extend your app’s controls across the system:

Additionally, for app intents related parts of controls, you can refer to the session Bring your app’s core features to users with App Intents.