Index the content in apps that handle persistent user data, such as documents and photos, and let users deep-link to it from Spotlight and Safari search results. Add, update, and delete searchable app content.
Language
- Swift
- Objective-C
SDK
- iOS 9.0+
Overview
The Core Spotlight framework helps your app participate in search by providing ways to index the content within your app (including user-generated content) and manage the on-device index. Use the APIs of the Core Spotlight framework to add, edit, and remove items from the on-device index.
Making App Content Searchable
To get started indexing app content, perform these steps:
Create a
CSSearchableItemAttributeSetobject and specify properties that describe the item you want to index.Create a
CSSearchableItemobject to represent the item. ACSSearchableItemobject has a unique identifier that lets you refer to it later.If needed, specify a domain identifier so that you can gather multiple items together and manage them as a group.
Associate the attribute set with the searchable item.
Add the searchable item to the index.
As you use Core Spotlight to make your app content searchable, you should also use NSUserActivity to make app states and navigation points searchable and to help users return to an activity or app location when they tap on a search result. (You can also use NSUserActivity APIs to mark an activity as public, which means that it can be shown to other users and can help encourage them to use your app.) Both Core Spotlight and NSUserActivity use a CSSearchableItemAttributeSet object to describe a searchable item and provide rich metadata that is displayed in search results. When you use both APIs, you can improve the ranking of your items in search results and prevent item duplication by specifying the same value in relatedUniqueIdentifier (NSUserActivity) and uniqueIdentifier (CSSearchableItem).
If your app has related content on a website, you should also mark up your website and support universal links to ensure that users can open your native app when they tap a search result supplied by your website (if your app isn’t installed, tapping the result opens Safari).