iOS 16 - how to get more than 1 AppIntents / AppShortcut

I've implemented 2 different AppIntents, each includes their own AppShortcutsProvider with phrases unique to each AppIntent. Individually, they work great. But, when I try to include both in my app, only the last one defined works.

In my ContentView.onAppear(), I've tried calling:

ShortcutsOne.updateAppShortcutParameters()
ShortcutsTwo.updateAppShortcutParameters()

and only those defined in ShortcutsTwo are recognized by Siri.

I've also tried including ShortcutsTwo's AppShortcut(intent:, phrases) into ShortcutOne's AppShortcutsProvider (since it's static var appShortcuts: is defined as an array, ie, [Shortcuts] - but that doesn't work either.

Overall, I've found the system to be rather temperamental. ie, I have had to power off my iPhone & reboot my Mac to get changes recognized.

Any thoughts on how to get 2 or more AppIntents to work in one app?

Answered by CryptoKoa in 745195022

I've hacked my way into a solution... turns out that:

  1. I only need to call .updateAppShortcutParameters() once
  2. that call to .updateAppShortcutParameters() needs to include an AppShortcut(intent:, phrases:) call for each AppIntent I've written
  3. the AppShortcutsProvider's appShortcuts:[AppShortcut] array is initialized in a way that I was not expecting... ie, you don't need []s around nor commas between array elements

so, this is what it looks like:

static var appShortcuts: [AppShortcut] {
    AppShortcut(intent:IntentOne(), phrases:["phrase 1"]  // no commas!
    AppShortcut(intent:IntentTwo(), phrases:["phrase 2"]
}
Accepted Answer

I've hacked my way into a solution... turns out that:

  1. I only need to call .updateAppShortcutParameters() once
  2. that call to .updateAppShortcutParameters() needs to include an AppShortcut(intent:, phrases:) call for each AppIntent I've written
  3. the AppShortcutsProvider's appShortcuts:[AppShortcut] array is initialized in a way that I was not expecting... ie, you don't need []s around nor commas between array elements

so, this is what it looks like:

static var appShortcuts: [AppShortcut] {
    AppShortcut(intent:IntentOne(), phrases:["phrase 1"]  // no commas!
    AppShortcut(intent:IntentTwo(), phrases:["phrase 2"]
}

Below code explains how to use multiple app intent shortcuts. You MUST use include (.applicationName) in phrases for each shortcuts to be visible in shortcut app and in spotlight section.

@available(iOS 16, *)
struct MyAppIntentShortcutsProvider: AppShortcutsProvider {
    
    @AppShortcutsBuilder static var appShortcuts: [AppShortcut] {
        AppShortcut(
            intent: ShortcutIntentOne(),
            phrases: [
                "Create \(.applicationName) intent",
            ],
            shortTitle: "first one",
            systemImageName: "person.fill.badge.plus"
        )
        AppShortcut(
            intent: ShortcutIntentTwo(),
            phrases: [
                "Create \(.applicationName) intent two",
            ],
            shortTitle: "second one",
            systemImageName: "list.clipboard.fill"
        )
    }

}
iOS 16 - how to get more than 1 AppIntents / AppShortcut
 
 
Q