How can I make my app provide shortcuts

Generated on 7/30/2024

1 search

Tailscan

This post is brought to you by Tailscan, the best devtool for Tailwind CSS.

To make your app provide shortcuts, you can use the App Intents framework. Here are the steps and key points to consider:

  1. Define Intents: Intents are actions that your app can perform, like opening a view or starting a specific task. They are the commands or verbs in your app.

  2. Create App Shortcuts: An app shortcut is a wrapper around an intent that highlights it as an important function of your app. This allows features like Spotlight and Siri to offer that function without needing your app to be running. You can pre-fill some or all of the parameters of the intent to make the shortcut more specific.

  3. Automatic Registration: The App Intents framework automatically detects the provider and handles registration, so your app shortcuts are available as soon as the app is installed. This means you don't need to write any registration code.

  4. Integration with System Features: App shortcuts can be used in various system features such as Spotlight, Siri, the action button, and Apple Pencil Pro. They also appear as actions in the Shortcuts app, where users can explore, combine, and remix them to create custom shortcuts.

  5. Code Example: Here is a brief code example to illustrate how to define an app shortcut:

    struct OpenPinnedTrailIntent: AppIntent {
        static var title: LocalizedStringResource = "Open Pinned Trail"
        
        func perform() async throws -> some IntentResult {
            // Your code to open the pinned trail
        }
    }
    
    struct MyAppShortcutsProvider: AppShortcutsProvider {
        static var appShortcuts: [AppShortcut] {
            return [
                AppShortcut(intent: OpenPinnedTrailIntent(), phrases: ["Open pinned trail in MyApp"])
            ]
        }
    }
    

    In this example, OpenPinnedTrailIntent is an intent that opens a pinned trail, and MyAppShortcutsProvider provides this intent as an app shortcut.

For more detailed guidance, you can refer to the session Bring your app’s core features to users with App Intents.

Relevant Sessions

Bring your app’s core features to users with App Intents

Bring your app’s core features to users with App Intents

Learn the principles of the App Intents framework, like intents, entities, and queries, and how you can harness them to expose your app’s most important functionality right where people need it most. Find out how to build deep integration between your app and the many system features built on top of App Intents, including Siri, controls and widgets, Apple Pencil, Shortcuts, the Action button, and more. Get tips on how to build your App Intents integrations efficiently to create the best experiences in every surface while still sharing code and core functionality.

Bring your app to Siri

Bring your app to Siri

Learn how to use App Intents to expose your app’s functionality to Siri. Understand which intents are already available for your use, and how to create custom intents to integrate actions from your app into the system. We’ll also cover what metadata to provide, making your entities searchable via Spotlight, annotating onscreen references, and much more.

Design App Intents for system experiences

Design App Intents for system experiences

App Intents power system experiences in controls, Spotlight, Siri, and more. Find out how to identify the functionality that’s best for App Intents, and how to use parameters to make these intents flexible. Learn how to use App Intents to allow people to take action outside your app, and see examples of when to navigate into your app to show contextual information.

What’s new in App Intents

What’s new in App Intents

Learn about improvements and all-new features with App Intents, and discover how this framework can help you expose your app’s functionality to Siri, Spotlight, Shortcuts, and more. We’ll show you how to make your entities more meaningful to the platform with the Transferable API, File Representations, new IntentFile APIs, and Spotlight Indexing, opening up powerful functionality in Siri and the Shortcuts app. Empower your intents to take people deep into your app with URL Representable Entities. Explore new techniques to model your entities and intents with new APIs for error handling and union values.