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?