Objective
Feel Spotlight This function is quite useful, can enhance the user active, increase the application content exposure probability.
Body
I. Implementation (IOS 9.0)
1.1 Adding indexes
var searchableitems = [Cssearchableitem] () for app in apps { Let Searchableitemattributeset = Cssearchableitemattributeset (Itemcontenttype:kuttypetext as String) s Earchableitemattributeset.title = App.label searchableitemattributeset.contentdescription = "Watch \ (APP.L Abel) LIVE on Shou ' Let Searchableitem = Cssearchableitem (uniqueIdentifier:app.id, Domainidentifier: " Appbundlerid.apps ", Attributeset:searchableitemattributeset) searchableitems.append (Sear Chableitem)} cssearchableindex.defaultsearchableindex (). Indexsearchableitems (Searchableitems , Completionhandler: {(error:nserror?) in if error = = nil {print ("initspotlight...com Pleted ")} else {print (" \ (Error) "}})
Be sure to add the above code to the child thread, slightly slower. You can request the data from the server in the Appdelegate and then add the index.
1.2 Receive Click events
@available (IOS 8.0, *)
func application (application:uiapplication, continueuseractivity useractivity: Nsuseractivity, Restorationhandler: ([Anyobject]?)-> Void)-> Bool {
if #available (IOS 9.0, *) {
if useract Ivity.activitytype = = Cssearchableitemactiontype {
if let uniqueidentifier = useractivity.userinfo?[ Cssearchableitemactivityidentifier] as? String, let label = useractivity.title {
//page Jump}}/Return
True
}
Ii. Additional Experience
2.1 Cssearchableitemattributeset
You can not set the Thumbnaildata, so the default is the current application of the LOGO, and also note that Thumbnailurl is not used to specify the network image address-#, so you need to add a thumbnail to the online download to the local and then set
2.2 Cssearchableitem
The default expiration is one months, and additional data is not available (for example, through the Cssearchableitemattributeset SetValue, the useractivity over there are not received)
2.3 No limit found on the number of indexed bars
Http://stackoverflow.com/questions/35284223/is-there-a-limit-for-number-of-items-cssearchableitem-in-core-spotlight-cssear
I found that the index is still very slow, and the other batch index did not understand, the feeling should be deleted and new words for batch processing.
2.4 No use finding a way to index a new method
Repeated calls are no problem, as long as the uniqueidentifier match will overwrite the old data
2.5 did not find a way to upgrade the rankings
It seems that the system will have a set of algorithms to automatically elevate rankings.
Summary: The above is the iOS development Core Spotlight instance application, as well as the experience share, hoped can help the development iOS schoolmate.