问题
How to decide which one is most suitable among CoreSpotlight framework & NSUserActivity for Search Programming.
回答1:
CoreSpotlight
- does not require users to visit the content in order to index it (index content at any point)
- private on-device index (you don’t use Core Spotlight APIs to make items publicly searchable)
NSUserActivity
- can index only as users perform activities in your app
- public/private indexing
- indexing navigation points
回答2:
In addition to @sash 's answer, you may want to watch WWDC 2015 Session 709 Introducing App Search
The same
userActivity
inapplication(_:continueUserActivity:restorationHandler:)
hasactivityType == CSSearchableItemActionType
- Utilize
CSSearchableItemAttributeSet
to describe attribute
The differences
CoreSpotlight
- Intend for indexing many items, making them searchable
- Describe attribute with
CSSearchableItem.attributeSet
- batching
- update, deleting
CoreSpotlight is for private data which is indexed on the device and you can use CoreSpotlight to comprehensively index data in your app.
If you're building or you have a social networking app for instance and you wanted to index all of the messages that the user has sent and received, CoreSpotlight is the right tool for the job.
NSUserActivity
- Intent for indexing current activity, making it convenient in Spotlight so that we can pick up
- Describe attribute with
contentAttributes
- Allow content to be in Apple cloud public in
eligibleForPublicIndexing
Use NSUserActivity for both public and private content as well as for indexing navigation points inside of your app.
Now there is another flavor of NSUserActivity that Dave touched on which is Public Indexing.
More about NSUserActivity
becomeCurrent
is for Handoff to start the broadcasting process- We may use
eligibleForHandoff = false
andeligibleForSearch = true
to get the nearly same effect asCoreSpotlight
- We must keep
NSUserActivity
objects around until the index work finishes - We don't know when the index work finishes
Designed to work together
These APIs while distinct, they're really designed to work together.
In the same app for the same content you can adopt multiple APIs.
The only thing to remember is for items that are indexed from multiple places, you want to connect these items by giving them the same ID.
More resources
- App Search Programming
- Integrating with iOS System Search
来源:https://stackoverflow.com/questions/33031087/what-is-the-basic-difference-between-using-nsuseractivity-corespotlight-framew