Search code examples
iosswiftsirikitsirishortcuts

How can I tell if my intent is running in the Shortcuts app?


In my app I have created a SiriKit intent that allows the user to search for people.

If they trigger this intent directly from Siri then I would like to open my app with this search string and show the results - I can do this by passing .continueInApp and an NSUserActivity to the completion handler.

However, if the intent is part of a flow in the Shortcuts app then I want to pass the results as an output from the intent handler - Again, I can do this by returning an array of results and .success to the completion handler.

My question is how can my handler determine the context in which it is running, so that it either launches my app or returns the result directly as is appropriate?


Solution

  • I may be wrong, but I don't think iOS exposes such information (originator, e.g. Siri or ShortCuts), as this would allow developers to define app behaviours that are different from the static definitions of their Intents (in which Siri/ShortCuts are supposed to act transparently). I doubt Apple would ever agree to that.

    IMO, if this is really what you want, the only option is to take a stack trace, identify if/where the calling function exhibits differences between Siri/ShortCuts are, and work it from there.

    Ugly, but it'll work.