How can I know which Widget or Live Activity invoked an AppIntent so the AppIntent can perform logic specific to only that instance?
You can do this by associating an object with a stable identifier with the data inside the Live Activity or Widget.
For example, for a recipe app, you could instantiate a Live Activites attributes with the recipes id
.
Then when you invoke your AppIntent, you can pass it as an argument, like so:
struct ExampleIntent: AppIntent {
// Configure your intents title and description
@Parameter(title: "id")
var id: String?
init() {} // A default initialiser is required to conform to Appintent
init(id: String) {
self.id = id
}
func perform() async throws -> IntentResult {
// use self.id here
}
}