4

I've setup an interactive Widget in iOS 17 which uses an AppIntent from an SPM package but nothing works when you tap on the button in the widget.

Supposedly you should be able to use AppIntentsPackage, which should make it possible to use AppIntents from other frameworks/SPM package(?), but I cannot get it to work. This is my setup:

SPMPackage

public struct MyAppIntent: AppIntent { ... } public struct MyAppIntentPackage: AppIntentsPackage { } 

WidgetExtension

import SPMPackage struct MyWidgetEntryView: View { var body: some View { Button(intent: MyAppIntent()) { Text("Tap here") } .containerBackground(...) } } extension MyWidgetBundle: AppIntentsPackage { static var includedPackages: [AppIntentsPackage.Type] = [ MyAppIntentPackage.self ] } 

Seems to have set it up exactly how Apple explains it in the documentation but it doesn't work. Am I missing something? Thanks!

2 Answers 2

7

Got word back from an Apple representative that having AppIntents in an SPM package is not yet supported.

I solved my issue by moving all the code related to AppIntents in to the WidgetExtension and now it works reliably.

Hope this helps someone else in the future, but more hopeful that this will be resolved in a future iOS version.

Sign up to request clarification or add additional context in comments.

2 Comments

I've been trying to do exactly this, I want to share the intent and TimelineProvider between widgets for phone and watch. Is there anyway to share code here?
thx, Good to know! But would also be good to have some official documentation on that. Have not seen this mentioned anywhere. Do you have some ticket or forum post mentioning it?
0

I had the same issue, and I think this is not supported by Apple. So what I do was moved out all things related to WidgetKit from my package, and put it on the main project that consumes the package and I pass intents by dependency injection where it is necessary.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.