7

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?

Paulw11
  • 108,386
  • 14
  • 159
  • 186

1 Answers1

6

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.

Alex
  • 1,581
  • 1
  • 11
  • 27
  • I suspect you may be right, but I am not sure about your reasoning - I have a similar problem if I provide a UI for my Siri Intent - Even when the intent is executed in a shortcut, the UI is still shown - There is clearly a difference between executing from Siri directly, where the user expects to see results, and executing in a shortcut flow where the user expects the results to be handed to the next step - ie. "Interactive" vs "non interactive". I will have a closer look at the SoupChef example – Paulw11 Sep 17 '19 at 08:42
  • After looking at the SoupChef sample it seems that their shortcut works the same way. The only solution seems to be to create two intents - One that is designed to be run from within the Shortcuts app and one that is designed to be invoked directly from Siri – Paulw11 Sep 17 '19 at 10:46
  • I came to the above conclusion using the 'SoupChef' example as well ;). There is a difference in user interface, I agree, but it's controlled by iOS, and for the case of Siri, Intents are explicit before hand. What you would like to have is a second set of intents applicable to ShortCuts only. It didn't appear to me that you could run two separate intents though, what their example says if I'm not mistaking is to expose, or not, Intents designed for Siri, to ShortCuts. I didn't see an option to make an intent for ShortCuts only. I may have missed something. – Alex Sep 17 '19 at 14:43
  • From a design perspective, It seems reasonable for apple to enforce the same interface for everyone (i.e., driven by a Siri interaction), to ensure a consistent behaviour everywhere. And this also facilitates current (and future) review process, otherwise, apple support would have to dig into separate call flows to make sure that the app doesn't try to ask more that what it is needed. Good Luck! – Alex Sep 17 '19 at 14:50
  • No, you can't limit the exposure of intents to Shortcuts, but at least the user could choose the appropriate intent. My use case is a contacts app. Sometimes you might want to trigger a search that shows the results on screen. In the context of the Shortcuts app you want the intent to simply return the list of contacts that can be passed to the next step in the shortcuts and nothing to be shown on the screen. It would be great if the one intent could react to its context to have the appropriate behaviour. – Paulw11 Sep 17 '19 at 19:58
  • I don't see how this would be a review issue; the intent definition still defines the inputs, outputs and descriptions of the intent. – Paulw11 Sep 17 '19 at 19:59
  • mmm... Yes, I agree, but review-wise, the call flow is difficult to check, since it is up to the dev at this point (since there are no ShortCuts specific intents). if the intent is to respond to 'find me some 3-stars Mexican Restaurants reviewed in XYZApp', and the answer is 1/ an underlying JSON frame with the said list, or 2/ a transition to a third-party app ViewController with the said list displayed, it's technically the same response, but a fundamentally different response from a UI perspective. Also, in 2/ the developer can choose to add whatever he sees fit, sometimes asking.. – Alex Sep 18 '19 at 08:14
  • more than what's needed. I think the core issue is that this situation mixes a user interaction w/ Apple's App & third-party app, within a single scenario, therefore pushing Apple to sort of 'vouching' for everything that will happen until completion. While your demand is perfectly acceptable, they chose to cut it short, to avoid complexity, and I suspect to facilitates the verification and control of what a third party app exchanges with a user while under the umbrella of a legit, user-facing iOS service. Hope this helps. – Alex Sep 18 '19 at 09:00
  • I don't really see that. The user is still in control of what information they provide. I think it is just not there yet - Prior to iOS 13 your intents couldn't send/receive data as part of a flow in Shortcuts - now they can. Hopefully they will add this in the future. – Paulw11 Sep 18 '19 at 09:13
  • I doubt that, especially because Apple Pay will process payments using Siri/ShortCuts as a front end, and a 3rd party app as a 'backend' for the business logic. "Siri/ShortCut buy me a subway ticket using XYZTravel", you want to make sure that the call flow can not leak out to XYZ interface (otherwise, who is responsible if it fails or the user's banking info is stolen?). There is no way to ensure a clear line of responsibility if a scenario can start on Apple, and continue on XYZTravel. So, IMO, while what you seek is legit, it's unlikely to happen. But that's just me, we'll see. Cheers! – Alex Sep 19 '19 at 06:21
  • Thanks, I suppose it's not the answer you hopped for, but thanks for the points. Hey, can I ask for your help? I have this question here https://stackoverflow.com/questions/57921856/apple-turicreate-always-return-the-same-label , I was wondering if you could have some inputs? I've shared all the necessary code so that anyone can give it a go in 30 sec. It's been bugging me for a while, and I'm out of strategy. Help much appreciated! – Alex Sep 24 '19 at 07:26