This document discusses how to make app content searchable using Core Spotlight and NSUserActivity on iOS. It provides steps to index app content using Core Spotlight, which is best for relatively static data. It also discusses using NSUserActivity to index user activities and dynamic content the user has interacted with. Both Core Spotlight and NSUserActivity use NSUserActivity and return search results in the userInfo dictionary, which can then be used to present relevant content to the user.
2. Core Spotlight Search
Full index of app content
NSuserActivity
Index of content that the user has interacted with
Both use NSUserActivity
Introduced in iOS 9 for third party developers
Core Spotlight
4. Core Spotlight
Makes your Apps private content searchable
Core Spotlight indexes your content
Best for relatively static data
5. Index your apps content
Create CSSearchableItem for each object to be
indexed
Each CSSearchableItem contains a
CSSearchableItemAttributeSet. Put the
metadata for Spotlight in here
Pass an array of CSSearchableItems to Core
Spotlight for indexing
Your Apps content appears in Spotlight search
9. userActivity.userInfo contains the unique identi鍖er you put
in the attribute set
Use it to present the relevant content
Step 4:Handle the search results
10. NSUserActivity
Indexes user activities
Best for dynamic content that the user has
interacted with
Also enables Handoff
11. Step 1: Create NSUserActivity
Give the activity type a unique identi鍖er
Always give an expiration date
User Info dictionary is returned in search results
Should contain all information needed to recreate the
activity
12. Step 2:In your View Controller
userActivity property of View Controller added in iOS 8
Related Unique identi鍖er is nil to avoid duplicate records
updateUserActivityState called periodically to keep activity up to date
13. userActivity.activityType contains the unique identi鍖er you set
when creating the user activity in step 1.
Use userActivity.userInfo dictionary to present the relevant content
Step 3:Handle the search results
14. Things to Note
In CoreSpotlight , the Related Unique
Identi鍖er in the Attribute set should be set to
the object ID. In NSUserActivity, it should be
nil.
Give User Activity an expiration date
Keep content relevant.