際際滷

際際滷Share a Scribd company logo
Make Your App
Searchable with Core
Spotlight
Marian OShea
 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
Core Spotlight search
Core Spotlight
 Makes your Apps private content searchable
 Core Spotlight indexes your content
 Best for relatively static data
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
Step 1: Create the Attribute Set
Step 2: Create the Searchable Item
Step 3: Create the Index
 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
NSUserActivity
 Indexes user activities
 Best for dynamic content that the user has
interacted with
 Also enables Handoff
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
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
 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
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.
Thank You!
https://github.com/primulaveris/CoreSpotlightDemo

More Related Content

Core Spotlight search

  • 1. Make Your App Searchable with Core Spotlight Marian OShea
  • 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
  • 6. Step 1: Create the Attribute Set
  • 7. Step 2: Create the Searchable Item
  • 8. Step 3: Create the Index
  • 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.