How does OpenIntent in a control widget actually open the app to the target feature?

I want to add a Control Center widget for my app that will open the app to a particular feature. I'm looking at the "Open your app with a control" example here, which seems like exactly what I want:

Set your control’s action to an app intent that conforms to OpenIntent to open your app when someone uses a control. Using OpenIntent allows you to take someone to a specific area of your app when a control performs its action.

The example doesn't show exactly how to hook up the LaunchAppIntent to a control widget, but I'm guessing it's something like this:

@available(iOS 18.0, *)
struct OpenFeatureControl : ControlWidget {
    var body: some ControlWidgetConfiguration {
        StaticControlConfiguration(kind: "com.example.OpenFeature") {
            ControlWidgetButton(action: LaunchAppIntent()) {
                Image(systemName: "book")
            }
        }
        .displayName("Launch Feature")
    }
}

But there's one critical piece missing here: how is the target feature actually opened? My initial assumption would have been that once the app launches or resumes, there's a call to some method like continueUserActivity that has a user-info dict with some key whose value is the LaunchAppEnum. But I've put breakpoints on all those methods in my app and none of them get called (I'm using UIKit scene lifecycle).

I also tried a regular AppIntent with a perform method that talks to my app directly:

@available(iOS 18.0, *)
struct OpenFeatureIntent : AppIntent {
    static let title: LocalizedStringResource = "Open My Feature"
    static let opensAppWhenRun: Bool = true
    
    init() {}
    
    func perform() async throws -> some IntentResult {
        //MAIN_APP is defined in Active Compilation Conditions in build settings
        #if MAIN_APP
        let url = URL(string: "myapp://openfeature")!
        UrlHandler.instance().handle(url)
        #endif
        
        return .result()
    }
}

But when run, this simply does nothing.

Launching an app directly to a particular view or feature seems like a common use-case for control widgets, and there are apps doing it, but I can't find an example of how it's supposed to work. And the docs are really not helpful. Can anyone provide the missing piece here? What's the expected plumbing in an OpenIntent that actually launches particular UI in the app?

It's also worth noting that the LaunchAppIntent as shown in that documentation page does nothing.

I've got a working sample app with a Control Center widget that writes something to UserDefaults and then opens the containing app. See here.

widgetURL is the API you'd want to use to ensure your app is opened to a certain location. You can use shared defaults as well but this process isn't always immediate as defaults must synchronize.

Lastly, UserDefault.standard won't work across processes in your app as setting it in your Intent code may be from your Widget target, making it unreadable. You should be using an App Group and UserDefaults(suiteName:) with your app group, which would make it available everywhere.

Rico

WWDR - DTS - Software Engineer

How does OpenIntent in a control widget actually open the app to the target feature?
 
 
Q