How to open app when an indexed entity is tapped in Spotlight?
Generated on 8/7/2024
1 search
To open an app when an indexed entity is tapped in Spotlight, you need to follow these steps:
-
Conform to the
IndexedEntity
Protocol: First, ensure that your entity conforms to the newIndexedEntity
protocol. This allows your app's entities to be indexed and searchable in Spotlight. -
Index Your Entities: In your app's initialization method, index your entities using
CSSearchableIndex
. For example, you can callindexAppEntities
onCSSearchableIndex
to index all your entities. -
Implement an Intent: Create an intent that can handle the entity. For instance, if you have a trail entity, you might have an
OpenTrailIntent
that accepts a trail entity as a parameter. -
Search and Tap: When a user searches for an entity in Spotlight and taps on the result, the intent you implemented will be triggered, and the app will open to the relevant content.
Here is a more detailed example from the session "What’s new in App Intents":
"First, I'll add conformance to the new
IndexedEntity
protocol to my trail entity. Then in my app's init method, I'll index all the trail entities from my data manager by callingindexAppEntities
onCSSearchableIndex
. And that's it. I'm now donating my trail entity content to Spotlight. Let's see it in action. First, I'll launch my app so the new entity indexing code has a chance to run. Now I'll search for one of my trails in Spotlight. We can see that my trail content is showing up as a search result, and because I have an open trail intent that accepts our trail entity as a parameter, I can tap on the result to go straight to it in the app."
For more information on integrating your app with Spotlight, you can refer to the chapter on "Spotlight integration" in the session "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.
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.
Platforms State of the Union
Discover the newest advancements on Apple platforms.
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.
Support semantic search with Core Spotlight
Learn how to provide semantic search results in your app using Core Spotlight. Understand how to make your app’s content available in the user’s private, on-device index so people can search for items using natural language. We’ll also share how to optimize your app’s performance by scheduling indexing activities. To get the most out of this session, we recommend first checking out Core Spotlight documentation on the Apple Developer website.