core spotlight search

15
Make Your App Searchable with Core Spotlight Marian O’Shea

Upload: marian-oshea

Post on 14-Apr-2017

81 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Core Spotlight search

Make Your App Searchable with Core

SpotlightMarian O’Shea

Page 2: Core Spotlight search

• 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

Page 3: Core Spotlight search
Page 4: Core Spotlight search

Core Spotlight

• Makes your App’s private content searchable

• Core Spotlight indexes your content

• Best for relatively static data

Page 5: Core Spotlight search

Index your app’s 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 App’s content appears in Spotlight search

Page 6: Core Spotlight search

Step 1: Create the Attribute Set

Page 7: Core Spotlight search

Step 2: Create the Searchable Item

Page 8: Core Spotlight search

Step 3: Create the Index

Page 9: Core Spotlight search

• userActivity.userInfo contains the unique identifier you put in the attribute set

• Use it to present the relevant content

Step 4:Handle the search results

Page 10: Core Spotlight search

NSUserActivity

• Indexes user activities

• Best for dynamic content that the user has interacted with

• Also enables Handoff

Page 11: Core Spotlight search

Step 1: Create NSUserActivity

• Give the activity type a unique identifier

• Always give an expiration date

• User Info dictionary is returned in search results

• Should contain all information needed to recreate the activity

Page 12: Core Spotlight search

Step 2:In your View Controller

• userActivity property of View Controller added in iOS 8

• Related Unique identifier is nil to avoid duplicate records

• updateUserActivityState called periodically to keep activity up to date

Page 13: Core Spotlight search

• userActivity.activityType contains the unique identifier 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

Page 14: Core Spotlight search

Things to Note

• In CoreSpotlight , the Related Unique Identifier 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.

Page 15: Core Spotlight search

Thank You! https://github.com/primulaveris/CoreSpotlightDemo