Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 866
Paulw11 Avatar asked Sep 13 '19 03:09

Paulw11


People also ask

Does shortcuts app have to be open?

You can run shortcuts with Siri and this will avoid having to open the Shortcuts app. You can also add or run a shortcut from the Home Screen of your iPhone.

How do I use app shortcuts?

Touch and hold the app, then lift your finger. If the app has shortcuts, you'll get a list. Touch and hold the shortcut. Slide the shortcut to where you want it.

What is intent in Apple?

An app intent includes the code you need to perform an action, and describes the data you require from the system. The system exposes your actions directly from the Shortcuts app and indirectly through natural language commands spoken to Siri.

Can Apple shortcuts interact with apps?

An action—the building block of a shortcut—is a single step in a task. Mix and match actions to create shortcuts that interact with the apps and content on your Apple devices, as well as with content and services on the Internet.


1 Answers

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.

like image 79
Alex Avatar answered Sep 30 '22 05:09

Alex