Inform iOS about AppShortcutsProvider

I've been following along with "App Shortcuts" development but cannot get Siri to run my Intent. The intent on its own works in Shortcuts, along with a couple others that aren't in the AppShortcutsProvder structure.

I keep getting the following two errors, but cannot figure out why this is occurring with documentation or other forum posts.

No ConnectionContext found for 12909953344
Attempted to fetch App Shortcuts, but couldn't find the AppShortcutsProvider.

Here are the relevant snippets of code -

(1) The AppIntent definition

struct SetBrightnessIntent: AppIntent {
    static var title = LocalizedStringResource("Set Brightness")
    static var description = IntentDescription("Set Glass Display Brightness")
    

    @Parameter(title: "Level")
    var level: Int?

    static var parameterSummary: some ParameterSummary {
        Summary("Set Brightness to \(\.$level)%")
    }

    func perform() async throws -> some IntentResult {
        guard let level = level else {
            throw $level.needsValueError("Please provide a brightness value")
        }
        
        if level > 100 || level <= 0 {
            throw $level.needsValueError("Brightness must be between 1 and 100")
        }
        
        // do stuff with level
        return .result()
    }
}

(2) The AppShortcutsProvider (defined in my iOS app target, there are no other targets)

struct MyAppShortcuts: AppShortcutsProvider {
    static var shortcutTileColor: ShortcutTileColor = .grayBlue
    
    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        AppShortcut(
            intent: SetBrightnessIntent(),
            phrases: [
                "set \(.applicationName) brightness to \(\.$level)",
                "set \(.applicationName) brightness to \(\.$level) percent"
            ],
            shortTitle: LocalizedStringResource("Set Glass Brightness"),
            systemImageName: "sun.max"
        )
    }
}

Does anything here look wrong? Is there some magical key that I need to specify in Info.plist to get Siri to recognize the AppShortcutsProvider?

On Xcode 16.2 and iOS 18.2 (non-beta).

Answered by DTS Engineer in 820176022

Thanks for that test project. That log about the missing AppShortcutsProvider is legitimate because you are using an integer parameter, which is causing your App Shortcuts to not appear. If you remove that parameter from the invocation phase, you'll see the App Shortcuts appear, and that message will go away. With that message out of the way, you can ignore the ConnectionContext message as log noise that is internal to the system.

—Ed Ford,  DTS Engineer

Just to add a bit of additional context: The errors happen when I ask Siri to do the action specified in the phrases array. It seems like Siri knows that my App should handle this, but then stumbles after.

I can't comment on the error messages, but if you have a small reproducible test project that produces either one of those errors that you can share, I'd like to see it.

On your question about phrases, App Shortcuts need to have defined values for the parameters, such as those defined by an AppEnum. A parameter in an App Shortcut with a large range of values, such as arbitrary strings or any integer in your case won't work with that parameter part of the invocation phrase.

—Ed Ford,  DTS Engineer

Uploaded my test project here (iCloud Drive link). It's basically the two code snippets above with some small changes.

With this sample, I was able to reproduce the "No ConnectionContext" error by running the App Shortcut within the Shortcuts app. Unfortunately it didn't seem like Siri was picking up on the shortcuts provider, so I never got the other error, nor could I reproduce the "No ConnectionContext" error via a Siri voice command.

And gotcha on the App Shortcut Parameters point. I don't think that was super explicit in the documentation - I understood that Primitive values should work and if I needed anything more complicated, an AppEnum or similar would be necessary. I appreciate the clarification.

Accepted Answer

Thanks for that test project. That log about the missing AppShortcutsProvider is legitimate because you are using an integer parameter, which is causing your App Shortcuts to not appear. If you remove that parameter from the invocation phase, you'll see the App Shortcuts appear, and that message will go away. With that message out of the way, you can ignore the ConnectionContext message as log noise that is internal to the system.

—Ed Ford,  DTS Engineer

In the case of brightness, I'm guessing I can use an AppEnum to perhaps set to fixed levels. However, is this the right way to add voice commands via Siri?

As an App Shortcut and for something like brightness, that's correct.

—Ed Ford,  DTS Engineer

Inform iOS about AppShortcutsProvider
 
 
Q