2

I have spent plenty of time to find benefit of NSUserActivity over CoreSpotlight, whether i couldn't find anything practically.

Actually, it couldn't index our item, which we set through NSUserActivity. I have attached my snippet below, which supposed to work as per apple documentation,however it won't.

        let personName = "Jon Doe"
        let activity = NSUserActivity(activityType: "com.SearchAPIs.test”)
        activity.userInfo = ["name": "Jon Doe"]
        activity.title = person.name
        let keywords = personName.componentsSeparatedByString(" ")
        activity.keywords = Set(keywords)
        activity.eligibleForSearch = true
        activity.eligibleForPublicIndexing = true
        activity.expirationDate = NSDate().dateByAddingTimeInterval(16666600)
        activity.becomeCurrent()

I would like to find answer of

Why we need to use NSUserActivity in way of search, since it can be possible with CoreSpotlight?

virus
  • 1,203
  • 13
  • 21
  • answer to your second question is here: http://stackoverflow.com/a/33768885/1757229 – sash Nov 17 '15 at 23:15

1 Answers1

4

According to Apple documentation

To guarantee that the activity and its metadata get indexed, you must hold a strong reference to the activity until it gets added to the index. There are two ways to do this: The first way is to assign the activity to a property in the controller object that creates the activity. The second way is to use the userActivity property of the UIResponder object. If you use the second way, you need to set the metadata—such as information in the userInfo property—in the updateUserActivityState: method; otherwise, the metadata you set on the activity will not be persisted.

You activity is deallocated before getting indexed and best to retain using self .

And the answer to your second question remains mystery to me.

Maybe its like the performance ,no of items in indexing, and importantly the public indexing which CoreSpotlight don't offer.We have to wait a little more to get the answer for your question.

  • @ user3745996 is it possible to index multiple activities at same time for e.g using for loop or someting else. – The iCoder Oct 19 '15 at 12:05