Any example code for NSUserActivity in SearchApi feature?

2.2k Views Asked by At

Can anybody please provide me tutorial or example code in NSUserActivity feature for SearchApi. I am doing lots of RND about this feature but didn't get proper code for this.

1

There are 1 best solutions below

2
On

An example would be:

let activity = NSUserActivity(activityType: "com.tutsplus.iOS-9-Search.displayShow")
activity.userInfo = ["name": detailItem.name, "genre": detailItem.genre, "time": detailItem.time]
activity.title = detailItem.name
var keywords = detailItem.name.componentsSeparatedByString(" ")
keywords.append(detailItem.genre)
activity.keywords = Set(keywords)
activity.eligibleForHandoff = false
activity.eligibleForSearch = true
//activity.eligibleForPublicIndexing = true
//activity.expirationDate = NSDate()

activity.becomeCurrent()

See this link for more information and examples