Mobile Development 12 min read

Implementing Dynamic Configurable Widgets on iOS with SwiftUI and IntentConfiguration

This article provides a step‑by‑step guide on converting static iOS widgets into dynamic, server‑driven configurable widgets using SiriKit Intent files, Intents extensions, SwiftUI views, image loading, user interaction handling, data sharing, and debugging techniques.

Beike Product & Technology
Beike Product & Technology
Beike Product & Technology
Implementing Dynamic Configurable Widgets on iOS with SwiftUI and IntentConfiguration

The article begins by explaining the limitations of static iOS widgets and the benefits of making them dynamically configurable through server‑provided options.

It outlines three key steps to transform a static widget: (1) creating a SiriKit Intent definition file, (2) adding an Intents Extension target, and (3) modifying the widget’s Swift code to use IntentConfiguration and IntentTimelineProvider instead of StaticConfiguration .

Detailed instructions are given for each step, including how to add a custom intent, set its category to View , enable the "Intent is eligible for widgets" option, and define parameters (Enums for static options and Types for dynamic options). The generated intent classes are highlighted, and a sample protocol implementation is shown:

@available(iOS 12.0, macOS 10.16, watchOS 5.0, *)
@available(tvOS, unavailable)

@objc(LJZDMultibleConfigurationIntentHandling)
public protocol LJZDMultibleConfigurationIntentHandling: NSObjectProtocol {
    /*! 
    @abstract Dynamic options methods - provide options for the parameter at runtime
    @discussion Called to query dynamic options for the parameter and this intent in its current form.
    @param  intent The input intent
    @param  completion The response block contains options for the parameter
    */
    @available(iOS 14.0, macOS 10.16, watchOS 7.0, *)
    @objc(provideMultChannelsOptionsCollectionForLJZDMultibleConfiguration:withCompletion:)
    func provideMultChannelsOptionsCollection(for intent: LJZDMultibleConfigurationIntent, with completion: @escaping (INObjectCollection?, Error?) -> Swift.Void)
}

It then discusses the requirement to build widget UI with SwiftUI, noting that only SwiftUI views (no UIViewRepresentable or NSViewRepresentable ) are allowed, and explains how to load images synchronously within getTimeline .

User interaction is covered by describing the use of widgetURL and Link modifiers to launch the main app, and how the app receives the URL via onOpenURL or the traditional application(_:open:options:) callbacks.

Data sharing between the widget extension and the host app is addressed through App Groups, with examples of NSUserDefaults , NSFileManager , and Keychain sharing.

Debugging tips include setting environment variables ( _XCWidgetKind , _XCWidgetFamily , _XCWidgetDefaultView ) and attaching to the widget process from Xcode.

Potential pitfalls such as missing configuration intents and Objective‑C/Swift bridging issues are highlighted, along with solutions like setting the Intent Definition Compiler language to Swift.

The article concludes with a summary of the required structures, protocols, and their relationships, and provides reference links to Apple’s WidgetKit and SwiftUI documentation.

mobile developmentiOSdynamic-configurationSwiftUIWidgetKitIntent
Beike Product & Technology
Written by

Beike Product & Technology

As Beike's official product and technology account, we are committed to building a platform for sharing Beike's product and technology insights, targeting internet/O2O developers and product professionals. We share high-quality original articles, tech salon events, and recruitment information weekly. Welcome to follow us.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.