コントロールウィジェットの実装方法を紹介してください。
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:
-
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.
-
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.
-
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.
-
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.
-
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.
Extend your app’s controls across the system
Bring your app’s controls to Control Center, the Lock Screen, and beyond. Learn how you can use WidgetKit to extend your app’s controls to the system experience. We’ll cover how you can to build a control, tailor its appearance, and make it configurable.
Bring your app’s core features to users with App Intents
Learn the principles of the App Intents framework, like intents, entities, and queries, and how you can harness them to expose your app’s most important functionality right where people need it most. Find out how to build deep integration between your app and the many system features built on top of App Intents, including Siri, controls and widgets, Apple Pencil, Shortcuts, the Action button, and more. Get tips on how to build your App Intents integrations efficiently to create the best experiences in every surface while still sharing code and core functionality.