core spotlight search

Post on 14-Apr-2017

81 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Make Your App Searchable with Core

SpotlightMarian O’Shea

• 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

• Makes your App’s private content searchable

• Core Spotlight indexes your content

• Best for relatively static data

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

Step 1: Create the Attribute Set

Step 2: Create the Searchable Item

Step 3: Create the Index

• 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

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 identifier

• 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 identifier is nil to avoid duplicate records

• updateUserActivityState called periodically to keep activity up to date

• 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

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.

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

top related