Shortcut/Action on Siri Watch Face with independent WatchOS app

I'm relatively new to making apps, and even newer to independent watch apps. As training, I'm making a watch app that I can use to log my water intake throughout the day. I've created a new intent definition file (see image 1) on which I've checked the marks for all the target memberships (the app, the WatchKit app, and the WatchKit extension). Furthermore, the target membership class is a public intent for the WatchKit extension.

When logging my water I execute the following code:
Code Block swift
let intent = INManager.intent(drink: item)
INManager.donateShortcuts(withIntent: intent)

and my IntentManager looks like this:
Code Block swift
import Foundation
import Intents
class IntentManager {
func intent(drink: Drink) -> LogDrinkIntent {
let intent = LogDrinkIntent()
intent.uuid = drink.id.uuidString
intent.name = drink.name
intent.emoji = drink.emoji
return intent
}
func donateShortcuts(withIntent intent:INIntent) {
var relevantShortcuts: [INRelevantShortcut] = []
if let relevantShortcut = defaultRelevantShortcut(withIntent: intent) {
relevantShortcuts.append(relevantShortcut)
}
INRelevantShortcutStore.default.setRelevantShortcuts(relevantShortcuts) { (error) in
if let error = error {
print("Failed to set relevant shortcuts: \(error))")
} else {
print("Relevant shortcuts set.")
}
}
}
private func defaultRelevantShortcut(withIntent intent: INIntent) -> INRelevantShortcut? {
if let shortcut = INShortcut(intent: intent) {
let relevantShortcut = INRelevantShortcut(shortcut: shortcut)
relevantShortcut.shortcutRole = .action
let template = INDefaultCardTemplate(title: "Log Drink")
relevantShortcut.watchTemplate = template
print("Returning relevant shortcut.")
return relevantShortcut
}
return nil
}
}

When logging a drink the confirmation Returning relevant shortcut. and Relevant shortcuts set. are printed. However, the Siri watch face doesn't update to include a link to my action. I really appreciate your time and help. I've had a hard time trying to find any details about this functionality. Thank you! If you need more details or such, feel free to ask.

Answered by DTS Engineer in 661821022
There are two concepts to start with:
  • Donations are for actions the user has taken in the app

  • Relevant shortcuts are for actions the user might want to take in the future, based on triggers like time and location, but hasn't taken in the app before

Applying that to your code, you should donate the INIntent through INInteraction, as that represents an action taken in the app. You might have actions for your app that qualify as relevant shortcuts, and so using INRelevantShortcutStore to seed those to the system is fine, but doing that as the donation mechanism as you have here isn't correct.

Please take a detailed look at the SoupChef sample code project to see how everything fits together. It's fairly comprehensive, and we specifically included watchOS support with relevant shortcuts to help you discover how all of the different parts of custom intents fit together into the user experience. In particular, the relevant shortcut example includes a unique menu item that's not in the iOS app specifically so you can trace how that runs through the system, from setting the relevant shortcut, to showing up on the watch face, to handling the intent contained by the relevant shortcut. Since SoupChef is also an iOS app, it can be helpful to use the "Force Sync Shortcuts to Watch" action found in the iOS Settings > Developer menu.
Accepted Answer
There are two concepts to start with:
  • Donations are for actions the user has taken in the app

  • Relevant shortcuts are for actions the user might want to take in the future, based on triggers like time and location, but hasn't taken in the app before

Applying that to your code, you should donate the INIntent through INInteraction, as that represents an action taken in the app. You might have actions for your app that qualify as relevant shortcuts, and so using INRelevantShortcutStore to seed those to the system is fine, but doing that as the donation mechanism as you have here isn't correct.

Please take a detailed look at the SoupChef sample code project to see how everything fits together. It's fairly comprehensive, and we specifically included watchOS support with relevant shortcuts to help you discover how all of the different parts of custom intents fit together into the user experience. In particular, the relevant shortcut example includes a unique menu item that's not in the iOS app specifically so you can trace how that runs through the system, from setting the relevant shortcut, to showing up on the watch face, to handling the intent contained by the relevant shortcut. Since SoupChef is also an iOS app, it can be helpful to use the "Force Sync Shortcuts to Watch" action found in the iOS Settings > Developer menu.
Shortcut/Action on Siri Watch Face with independent WatchOS app
 
 
Q