WidgetKit
Build glanceable Home Screen widgets, Lock Screen complications, Control Center controls, and StandBy or CarPlay widgets using WidgetKit. Targets Swift 6.3 / iOS 26+.
Contents
Extension Architecture
- Separate extension target: Widgets run in an out-of-process widget extension.
- Shared storage with App Groups: Use
UserDefaults(suiteName: "group.com.example.app") or shared container directories to share data between the main app and the widget.
- Widget Bundle: Group all widgets, live activities, and controls in a single
@main WidgetBundle.
@main
struct AppWidgetsBundle: WidgetBundle {
var body: some Widget {
OrderStatusWidget()
QuickActionControl()
}
}
Widget Families and Surfaces
| Surface |
Supported Families |
Configuration |
Key API |
| Home Screen |
.systemSmall, .systemMedium, .systemLarge, .systemExtraLarge |
AppIntentConfiguration |
containerBackground(for:) |
| Lock Screen |
.accessoryCircular, .accessoryRectangular, .accessoryInline |
StaticConfiguration |
Monochrome / accented styling |
| StandBy |
.systemSmall, .systemMedium |
Same as Home Screen |
Night mode / red tint adaptation |
| Control Center |
ControlWidget (buttons & toggles) |
StaticControlConfiguration |
ControlWidgetButton, ControlWidgetToggle |
Timeline Management and Reload Budgets
Timelines provide entries into the future:
.atEnd: Requests a new timeline after the last entry date passes.
.after(Date): Schedules a reload at a specific future timestamp.
.never: Never reloads automatically; relies on app foreground reloads or push notifications.
[!IMPORTANT]
The system enforces a daily reload budget (typically 40-70 reloads per day). Do not schedule sub-minute reloads with .after. For urgent real-time state, push remote updates via push-notifications or use activitykit Live Activities.
Interactive Controls and Intent Handoff
Widgets support interactive buttons and toggles:
- Use
Button(intent:) and Toggle(isOn:intent:) conforming to AppIntent.
- Route detailed intent modeling and parameter resolution to
app-intents.
- Route Dynamic Island and Lock Screen real-time progress to
activitykit.
Route by Task
- For timeline provider setups, deep link handling (
widgetURL), and configurable intents, read Timelines, Configuration, and Deep Links.
- For Live Activity registration in widget bundles and push-to-update tokens, read Live Activity Presentation and Push.
- For memory budget limits, container backgrounds, and relevance entries for Smart Stacks, read Performance, Setup, and Lifecycle.
Common Mistakes
- Performing network requests or expensive computations inside the SwiftUI widget view instead of the
TimelineProvider.
- Hardcoding views without
.containerBackground(for: .widget), breaking iOS 17+ StandBy and Lock Screen rendering.
- Scheduling timeline reloads every few seconds, rapidly exhausting the daily reload budget.
- Forgetting App Group entitlement when reading data stored by the main app.
- Attempting to display videos, web views, or complex continuous animations in widget views.
Review Checklist
References
1---2name: widgetkit3description: Builds or reviews WidgetKit widgets and controls for Home Screen, Lock Screen, StandBy, CarPlay, and Control Center. Use for timelines, App Intent configuration, interactive controls, push reloads, refresh budgets, deep links, Smart Stack relevance, rendering, extensions, and App Groups.4---56# WidgetKit78Build glanceable Home Screen widgets, Lock Screen complications, Control Center controls, and StandBy or CarPlay widgets using `WidgetKit`. Targets Swift 6.3 / iOS 26+.910## Contents1112- [Extension Architecture](#extension-architecture)13- [Widget Families and Surfaces](#widget-families-and-surfaces)14- [Timeline Management and Reload Budgets](#timeline-management-and-reload-budgets)15- [Interactive Controls and Intent Handoff](#interactive-controls-and-intent-handoff)16- [Route by Task](#route-by-task)17- [Common Mistakes](#common-mistakes)18- [Review Checklist](#review-checklist)19- [References](#references)2021## Extension Architecture22231. **Separate extension target**: Widgets run in an out-of-process widget extension.242. **Shared storage with App Groups**: Use `UserDefaults(suiteName: "group.com.example.app")` or shared container directories to share data between the main app and the widget.253. **Widget Bundle**: Group all widgets, live activities, and controls in a single `@main` `WidgetBundle`.2627```swift28@main29struct AppWidgetsBundle: WidgetBundle {30 var body: some Widget {31 OrderStatusWidget()32 QuickActionControl()33 }34}35```3637## Widget Families and Surfaces3839| Surface | Supported Families | Configuration | Key API |40|---|---|---|---|41| Home Screen | `.systemSmall`, `.systemMedium`, `.systemLarge`, `.systemExtraLarge` | `AppIntentConfiguration` | `containerBackground(for:)` |42| Lock Screen | `.accessoryCircular`, `.accessoryRectangular`, `.accessoryInline` | `StaticConfiguration` | Monochrome / accented styling |43| StandBy | `.systemSmall`, `.systemMedium` | Same as Home Screen | Night mode / red tint adaptation |44| Control Center | `ControlWidget` (buttons & toggles) | `StaticControlConfiguration` | `ControlWidgetButton`, `ControlWidgetToggle` |4546## Timeline Management and Reload Budgets4748Timelines provide entries into the future:49- `.atEnd`: Requests a new timeline after the last entry date passes.50- `.after(Date)`: Schedules a reload at a specific future timestamp.51- `.never`: Never reloads automatically; relies on app foreground reloads or push notifications.5253> [!IMPORTANT]54> The system enforces a daily reload budget (typically 40-70 reloads per day). Do not schedule sub-minute reloads with `.after`. For urgent real-time state, push remote updates via `push-notifications` or use `activitykit` Live Activities.5556## Interactive Controls and Intent Handoff5758Widgets support interactive buttons and toggles:59- Use `Button(intent:)` and `Toggle(isOn:intent:)` conforming to `AppIntent`.60- Route detailed intent modeling and parameter resolution to `app-intents`.61- Route Dynamic Island and Lock Screen real-time progress to `activitykit`.6263## Route by Task6465- For timeline provider setups, deep link handling (`widgetURL`), and configurable intents, read [Timelines, Configuration, and Deep Links](references/timelines-configuration-and-deep-links.md).66- For Live Activity registration in widget bundles and push-to-update tokens, read [Live Activity Presentation and Push](references/live-activity-presentation-and-push.md).67- For memory budget limits, container backgrounds, and relevance entries for Smart Stacks, read [Performance, Setup, and Lifecycle](references/performance-setup-and-lifecycle.md).6869## Common Mistakes7071- Performing network requests or expensive computations inside the SwiftUI widget view instead of the `TimelineProvider`.72- Hardcoding views without `.containerBackground(for: .widget)`, breaking iOS 17+ StandBy and Lock Screen rendering.73- Scheduling timeline reloads every few seconds, rapidly exhausting the daily reload budget.74- Forgetting App Group entitlement when reading data stored by the main app.75- Attempting to display videos, web views, or complex continuous animations in widget views.7677## Review Checklist7879- [ ] App Group configured on both app and widget extension targets80- [ ] Timeline entries include future dates with appropriate reload policy (`.atEnd`, `.after`)81- [ ] Widget views support all declared `supportedFamilies`82- [ ] `.containerBackground` applied to all widget content views83- [ ] Accessory families designed for high-contrast, monochrome display84- [ ] Interactive controls trigger `AppIntent` without launching the main app unnecessarily85- [ ] Daily reload budget respected; urgent changes pushed via APNs8687## References8889- [Timelines, configuration, and deep links](references/timelines-configuration-and-deep-links.md)90- [Live Activity presentation and push](references/live-activity-presentation-and-push.md)91- [Performance, setup, and lifecycle](references/performance-setup-and-lifecycle.md)92- [WidgetKit documentation](https://sosumi.ai/documentation/widgetkit)93- [Widget](https://sosumi.ai/documentation/widgetkit/widget)94- [TimelineProvider](https://sosumi.ai/documentation/widgetkit/timelineprovider)