How do I view the menu in the SoupChef sample using Siri or Search?

How do I view the menu in the SoupChef sample using Siri or Search?

Replies

There are two ways to do this. The Soup Chef project uses NSUserActivity for this -- see the `viewMenuActivity` in the project. As a NSUserActivity based shortcut, using this as a shortcut will open the app and display the relevant view controller in the app.


The other way you can do this is by creating a custom intent for this purpose, and classify it as an "View" intent in the intent editor, and build a view controller with the menu in your IntentsUI extension.


If you're asking how to do this because you want an interactive experience of showing the menu and then placing the order all within a Shortcut, that is not possible. A Shortcut is meant to be focused on a discrete action the user frequently takes that can be completed quickly.

I actually meant that I thought that functionality was already there. I was trying to figure out how to use that functionality. Are you saying that as it is, SoupChef is not able to do that and that I would have to add code to it for SoupChef to be able to do that?

The view menu activity is set as part of the segue to the menu view controller. See the following in OrderHistoryTableViewController:

else if segue.identifier == SegueIdentifiers.soupMenu.rawValue {
            if let navController = segue.destination as? UINavigationController,
                let menuController = navController.viewControllers.first as? SoupMenuViewController {
                
                if let activity = sender as? NSUserActivity, activity.activityType == NSStringFromClass(OrderSoupIntent.self) {
                    menuController.userActivity = activity
                } else {
                    menuController.userActivity = NSUserActivity.viewMenuActivity
                }
            }
        }

With this, this activity is donated to the system, and will be available in Search as "Order Lunch." It can be available in Siri as well if you add a voice phrase to this shortcut in the iOS Settings app.

I can’t find “order lunch” in search nor in the settings app under Siri and search. There is a short cut in the settings app for “order 1 tomato soup” as well as two other shortcuts for ordering clam chowder. The SoupChef documentation said that I could view the menu using Siri.