Siri Shortcuts on Apple Watch

Learn how to take advantage of Siri and Shortcuts on the Apple Watch without any intervention required from the iOS companion app. By Mark Struzinski.

Leave a rating/review
Download materials
Save for later
Share

In iOS 14 and watchOS 7, Apple extended Shortcuts to the Apple Watch. Shortcuts can now run directly on the watch. While the phone is still necessary to create shortcuts, the watch can run them independently.

In this tutorial, you’ll:

  • Take advantage of shortcuts and Siri on the Apple Watch.
  • Create shortcuts for your app that run independently on the watch.
  • Enable Siri to function with your app through the watch, without any intervention required from the iOS companion app.
  • Add a shortcut for your app on the watch face.
  • A paid Apple Developer account.
    • This tutorial uses App Groups to share data between the apps and the intents you’ll build. Using App Groups requires some portal setup and a paid developer account.
  • A physical iPhone running iOS 14 and an Apple Watch running watchOS 7.
    • Although it’s possible to test the watch app from the simulator, it’s impossible to build and test intents on the simulator. To see your intents in action, you need a physical watch.
Note: To follow along with this entire tutorial, you need:
  • A paid Apple Developer account.
    • This tutorial uses App Groups to share data between the apps and the intents you’ll build. Using App Groups requires some portal setup and a paid developer account.
  • A physical iPhone running iOS 14 and an Apple Watch running watchOS 7.
    • Although it’s possible to test the watch app from the simulator, it’s impossible to build and test intents on the simulator. To see your intents in action, you need a physical watch.

Please make sure you sign into Xcode with your developer account. This allows automatic provisioning to create all the necessary app identifiers and provisioning profiles as you work through this tutorial.

Getting Started

Download the starter project by clicking the Download Materials button at the top or bottom of the tutorial. Open the app in the starter directory. This app assists in tracking your hydration intake throughout the day. It runs on the phone and the watch. Before you check it out, you need to make sure you have your simulator set up with a paired Apple Watch.

If you don’t already have an iPhone simulator paired with a watch, follow these steps:

Adding a new simulator dialog

Adding a new simulator dialog 2

Run destination showing phone simulator with paired apple watch

  1. In Xcode, select Window ▸ Devices and Simulators.
  2. Select Simulators on the top left.
  3. Click + on the bottom left to add a new simulator.
  4. In the dialog, fill in the following information:
    • Simulator Name: Make this something that describes the combination of phone and watch.
    • Device Type: Select any device you like here.
    • OS Version: iOS 14.3 or the latest SDK.
    • Check Paired Apple Watch.

    Adding a new simulator dialog

  5. Click Next.
  6. In the second step, fill in the following information:
    • Paired Simulator Name: Anything that accurately describes the watch simulator you want to use.
    • Device Type: Select any device you like here.
    • OS Version: watchOS 7.2 or the latest SDK.

      Adding a new simulator dialog 2

  7. Click Create.
  8. Your newly created simulator pair will now appear in the Run Destination list:

    Run destination showing phone simulator with paired apple watch

Running the App

You can now run the app and access it from both the phone and watch simulators. First, check out the iOS app.

  1. Select Hydrator from the scheme menu and select your paired phone and watch simulator in the Run Destination menu.
  2. Build and run.
  3. Add a few hydration entries by tapping Create New Entry.
  4. Check out the list of entries on the main view.

iPhone Hydrator screen showing some entries

Next, check out the app on the watch.

  1. Switch the active scheme to HydratorWatch.
  2. Build and run again.
  3. Tap + and add some hydration entries to see them populate in the list.

Watch Simulator

Note: This article focuses on adding and running shortcuts on the Apple Watch. Data sync between the phone and watch is beyond the scope of this article. Data added to the iOS app is independent of the watch app.

The app uses frameworks and app groups to share some code between the iOS app, watch app and extensions. This work is complete already. You’re just pulling in the frameworks when necessary to read and save data.

Setting up Portal Requirements

The starter project uses .xcconfig files to propagate build settings across all targets.

Creating an App Group

Before you configure your project, you need to create an App Group.

  1. Log in to the developer portal using your account.
  2. Select Certificates, IDs & Profiles from the sidebar.
  3. Now, choose Identifiers and press the blue + button to create a new identifier.
  4. From the list of options available, select App Groups.
    App Group Config
  5. Fill in Description and Identifier. Note that the identifier will add group automatically at the beginning. Also, try to use reverse domain notation as recommended.
    App Group Configuration step 2

Configuring Your Account

Perform these setup steps to get going:

  1. In the Xcode Project navigator, find the Resources/config folder.
  2. Open base.xcconfig.
  3. Update the value of BASE_DOMAIN to include a unique string. Apple recommends reverse domain notation here, like com.yourcompanyname.
  4. Update the DEVELOPMENT_TEAM value, replacing YOUR-TEAM-ID-HERE with your Team ID from the developer portal. If you’re not sure what it is, log in to the Apple Developer portal. Click the Account tab and then select Membership from the left sidebar. Your Team ID is on this page.
    Apple Account Team ID
  5. Update GROUP_ID, replacing YOUR-GROUP-ID-HERE with the value you already created in your Apple account.
  6. Save the .xcconfig file by pressing Command-S.

Understanding Siri Shortcuts and Intents

When you build your app for Siri Shortcuts, you have two options: NSUserActivity-based shortcuts and intents-based shortcuts. By far, the more flexible and robust option is to use intents-based shortcuts. They give you more options in accepting parameters, conflict resolution and a robust object model for input.

Using NSUserActivity-Based Shortcuts

Shortcuts that use the NSUserActivity API require an app launch to function. They’re unable to execute requests in the background with Siri. In your watch app, NSUserActivity-based shortcuts will attempt to open the watch app to execute first. If there’s no watch app present, the shortcut fails.

Using Intents-Based Shortcuts

Intents-based shortcuts can run locally via an extension, through the watch app or remotely on the phone. An intents-based shortcut that starts on the watch follows this flow:

  1. First, if it’s possible to handle the shortcut on the watch — because an intents extension is present on the watch — then the watch handles the shortcut locally.
  2. If no intent extension is present on the watch, then the watch attempts remote execution on the paired iPhone.
  3. Next, if the shortcut requires an app launch, then the shortcut fails. Shortcuts started from the watch cannot launch their iOS app counterpart to execute.
  4. Lastly, if the extension can run in the background on the iOS device, it’s executed there.