Hi there,
I successfully created an AppIntent for our app, and when I had it in the same target as our main app it showed up fine in the shortcuts app.
Then I realized that many of the new System Control widgets introduced in iOS 18 (e.g. lockscreen, control center) live in the widget extension target, but they also need to reference that same AppIntent. So to fix this, I thought I'd migrate out the code into it's own SPM package that both the WidgetExtension and the Main App processes can reference. However, after doing that and rebuilding, the intent no longer shows up in the Shortcuts app. Furthermore, my AppShortcutsProvider
class now has this error when trying to define the list of appShortcuts
:
App Intent
<name>
should be in the same target as AppShortcutsProvider
Is this intended, and if so, how do we reference the same AppIntent across multiple targets?
When defining your types for App Intents in a different module, take care to make sure that you have a type conforming to AppIntentsPackage in both the module containing the types, as well as the module referring to those types. This is one of the most overlooked elements when setting this up.
Only framework types are supported for the module, and I suggest sticking to Xcode targets for that. Swift packages, in their default configuration, can link as either a static library or a dynamic library, depending on the surrounding build context to make an optimal choice, and that is our general recommendation for packages, but in this scenario for App Intents, means you might link as a static library, rather than as a dynamic library. Further, if you compare the build log for an Xcode framework target and for a Swift package target congigfued to be dynamic using Xcode 16 beta 4, you'll also notice that the Xcode framework target has a build step for extracting app intent metadata that the Swift package build does not. This intent metadata extraction step is important.
how do we reference the same AppIntent across multiple targets?
One thing you can do is include the source file in multiple targets, like a main app target and an app extension target.
— Ed Ford, DTS Engineer