What is the basic difference between using NSUserActivity & CoreSpotlight framework for Search programming? How to choose among them?

扶醉桌前 提交于 2020-01-03 18:55:08

问题


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 in application(_:continueUserActivity:restorationHandler:) has activityType == 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 and eligibleForSearch = true to get the nearly same effect as CoreSpotlight
  • 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!