I am working on building Control widgets for our app and have noticed that openAppWhenRun doesn't seem to work for any ControlConfigurationIntent. When attaching the debugger to the widget extension in a sample project, I see the following error:
Unknown NSError The operation couldn’t be completed. (LNActionExecutorErrorDomain error 2018.)
This is reproducible as of Xcode 16.0 Beta 2 and Beta 3.
I have noted that using an OpenIntent,
with a parameter called target
that conforms to AppEnum
seems to open the app properly, but if I use that workaround, adding any additional parameters to the OpenIntent
seems to break things again.
Are others seeing this issue? I have feedback FB14357691. Here's some sample code below to reproduce:
var body: some ControlWidgetConfiguration {
AppIntentControlConfiguration(kind: "Open Any Screen", intent: OpenAppScreenIntent.self) { template in
ControlWidgetButton(action: template) {
Label {
Text("Open App")
} icon: {
Image(systemName: "calendar")
}
}.tint(.red)
}
}
}
enum AppScreen: CaseIterable {
case calendar
case campus
case search
var title: String {
switch self {
case .calendar:
"Calendar"
case .campus:
"Campus"
case .search:
"Search"
}
}
}
struct OpenAppScreenIntent: ControlConfigurationIntent {
static var title: LocalizedStringResource = "Open app to a screen"
static var description = IntentDescription("Opens the app.")
/// The app should open regardless of what happens here
static let openAppWhenRun: Bool = true
@Parameter(title: "Screen", optionsProvider: OsuScreenOptionsProvider())
var screen: String?
struct OsuScreenOptionsProvider: DynamicOptionsProvider {
func results() async throws -> ItemCollection<String> {
var screenTitles: [String] = []
for screen in AppScreen.allCases {
async let title = screen.title
await screenTitles.append(title)
}
return ItemCollection {
ItemSection(items: screenTitles.map { IntentItem($0)})
}
}
func defaultResult() async -> String? {
return "Campus"
}
}
@MainActor
func perform() async throws -> some IntentResult {
#warning("The app should open regardless of what happens in this method, but it doesn't")
return .result()
}
}
I have discovered a workaround here:
https://developer.apple.com/forums/thread/758637
It would be nice if we could get an explanation or some diagnostics as to why we need to add our control widgets to the app itself, when they are supposed to reside in an extension or Widget Bundle, since in fact, the Xcode project / target creation tool will put the default Control in an extension target only causing the above code to not work.