AppIntentsPackage protocol with SPM package not working

Hi,

I am trying to integrate the new AppIntentsPackage protocol into my application. Especially what I want to do is to create a dedicate SPM package which holds all my app intents and then share that with my widget extension for Widget intents as well as the main iOS app for powering an AppShortcutProvider. Unfortunately I run into an issue here.

I have the following explanatory setup:

  1. SPM package called ProjectAppIntents
  2. iOS target

My AppIntents SPM package

//Package: ProjectAppIntents

public struct TestAppIntent: AppIntent {
    public static var title: LocalizedStringResource = "TestAppIntent"

    @Parameter(title: "Parameter1", optionsProvider: ParameterOptionProvider())
    public var parameter: String


    public init(parameter: String) {
        self.parameter = parameter
    }

    public init() { }

    public func perform() async throws -> some IntentResult & ReturnsValue {
        .result(value: 5)
    }
}

struct ParameterOptionProvider: DynamicOptionsProvider {
    func results() async throws -> [String] {
        return ["Hello", "World"]
    }
}

public struct ProjectAppIntentsPackage: AppIntentsPackage { }

My iOS app

// Target: iOS

import ProjectAppIntents

struct ProjectApp: App {

 var body: some Scene {
        WindowGroup {
          ContentView()
        }
    }
}


extension ProjectApp: AppIntentsPackage {
    static var includedPackages: [AppIntentsPackage.Type] = [
        ProjectAppIntentsPackage.self
    ]
}

struct ProjectShortcuts: AppShortcutsProvider {
    static var appShortcuts: [AppShortcut] {
        AppShortcut(
            intent: TestAppIntent(),
            phrases: ["Start a \(.applicationName)"],
            shortTitle: "Hello World",
            systemImageName: "house"
        )
    }
}

When I now try to compile my app, I get the following build error:

2023-06-25 09:53:47.853 appintentsnltrainingprocessor[44848:2059163] Parsing options for appintentsnltrainingprocessor
2023-06-25 09:53:47.854 appintentsnltrainingprocessor[44848:2059163] Starting AppIntents SSU YAML Generation
2023-06-25 09:53:47.868 appintentsnltrainingprocessor[44848:2059163] error: The action TestAppIntent referenced in App Shortcut does not exist
Command AppIntentsSSUTraining failed with a nonzero exit code

So for me it seems like the compiler cannot find the AppIntent defined in an SPM package.

Am I doing something wrong here or does the AppIntentsPackage protocol not work with SPM packages ?

Thanks a lot for helping !

+1. I have roughly the same setup except I'm using a dynamic framework instead of a SPM package. I got the same error when I reference my AppIntent in a AppShortcutsProvider.

Weirdly enough I just discovered that prefixing all the AppShortcut types with AppIntents fixed the issue for me.

import AppIntents
import MyIntentsFramework

struct MyShortcutsProvider: AppShortcutsProvider {
    static var appShortcuts: [AppIntents.AppShortcut] {
        AppIntents.AppShortcut(
            intent: MyAppIntent(),
            phrases: ["Open \(.applicationName)"],
            shortTitle: "Title",
            systemImageName: "plus"
        )
    }
}

Hey @joeycarmello thanks a lot for your hint. This actually fixes the compilation error, so building works fine but then the app shortcut does not show up in the Shortcuts app. But if I then remove the prefixes again and build again it works. But - if I then do a clean and try to build again it fails with the initial error message. All in all, very weird tbh. I currently assume that the setup I have is not fully compatible with the current beta. Which I really do hope gets fixed with the next beta though.

Agree, I'm seeing the same thing here. It looks like prefixing AppIntents. in the shortcut provider actually just hides the shortcuts entirely from the metadata parser. if you look at the built Metadata.appintents/extract.actionsdata in derived data, it's clear the AppShortcutsProvider is detected correctly but that the intents, entities, and queries are not detected from the underlying package / framework. Assuming a beta bug with the package intent re-exporting at this point, too.

Seems to still not work in Xcode 15.0 Beta 3. I do still see the same error messages mentioned in the initial post. Feedback filed under: FB12550171

I have also not been able to get AppIntentsPackage working. I’m copying and pasting the example from Apples documentation, but no shortcuts appear in the shortcuts app.

Has anybody been able to resolve this? I'm experiencing an issue where I can build and run in Debug, but when I try to build Release version of my app with an AppShortcutsProvider defined I get the "Command AppIntentsSSUTraining failed with a nonzero exit code" error. So, I'm able to run my builds locally, but I can't submit anything to TestFlight or the App Store.

As of beta 7 here I can build and run the project without any errors (though this is only for debug, I haven't tried a release build yet), but AppShortcuts defined in the package don't show up in the Shortcuts app

With Xcode 15 now released, I was still not able to get my setup to work. Still running into the "Command AppIntentsSSUTraining failed with a nonzero exit code" error

Has anyone found a solution to this?

I am still having the same issue, and had to release an app without an AppShortcutsProvider, but as a result my shortcuts do not show up in the Shortcuts app and do not get suggested to users throughout iOS.

As far as I can tell, reexporting an AppIntent defined in a framework using AppIntentsPackage and includedPackages has never worked since it was introduced at WWDC23. @gohnjanotis @alexanderwe I believe the only solution is to add your app intents directly to your app target and also any other extension target that uses them, I was able to get my shortcuts showing up in Shortcuts doing this. Unfortunately this workaround wouldn't work for an AppIntent defined in an SPM package like in the original question prompt.

I finally figured out the issue and build error I was seeing related to this error.

My app minimum target is iOS 16, and I was using a version of AppShortcut.init that is only available in iOS 17.

I updated my AppShortcutsProvider code as follows to be able to still support iOS 16, and also the iOS 17 version:

struct AppShortcuts: AppShortcutsProvider {

    static private let phrases: [AppShortcutPhrase<DoMyIntent>] = {
        return ["Do Intent in \(.applicationName)"]
    }()

    static var appShortcuts: [AppShortcut] {
        if #available(iOS 17.0, *) {
            return [
                AppShortcut(
                    intent: DoMyIntent(),
                    phrases: phrases,
                    shortTitle: "DoIntent",
                    systemImageName: "calendar"
                )
            ]
        }
        else {
            return [
                AppShortcut(
                    intent: DoMyIntent(),
                    phrases: phrases
                )
            ]
        }
    }
}

This is still an issue as of Xcode 16.0 beta 4. FB14507102

This is still an issue as of Xcode 16.1 Beta.

AppIntentsPackage protocol with SPM package not working
 
 
Q