What is the basic difference between using NSUserA

2019-06-25 05:09发布

How to decide which one is most suitable among CoreSpotlight framework & NSUserActivity for Search Programming.

2条回答
萌系小妹纸
2楼-- · 2019-06-25 05:55

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
查看更多
Explosion°爆炸
3楼-- · 2019-06-25 05:56

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

查看更多
登录 后发表回答