Objective
Feel Spotlight This function is quite useful, can enhance the user active, increase the application content exposure chance.
Statement
Welcome reprint, but please keep the original source of the article:)
Blog Park: http://www.cnblogs.com
Farmer Uncle: Http://over140.cnblogs.com
Body
First, implementation (IOS 9.0)
1.1 Adding an Index
var searchableitems =[Cssearchableitem] () forAppinchApps {Let Searchableitemattributeset= Cssearchableitemattributeset (itemcontenttype:kuttypetext asString) Searchableitemattributeset.title=App.label searchableitemattributeset.contentdescription="Watch \ (App.label) LIVE on Shou"Let Searchableitem= Cssearchableitem (Uniqueidentifier:app.ID, Domainidentifier:"Youappbundlerid.apps", Attributeset:searchableitemattributeset) Searchablei Tems.append (Searchableitem)} cssearchableindex.defaultsearchableind EX (). Indexsearchableitems (Searchableitems, Completionhandler: {error:nserror?)inch ifError = =Nil {print ("initspotlight...completed") } Else{print ("\ (Error)") } })
It is important to note that the above code is added to the child thread to execute, slightly slower. You can request data from the server in Appdelegate and then index it.
1.2 Receive Click events
@available (IOS8.0, *) Func application (application:uiapplication, Continueuseractivity useractivity:nsuseractivity, Restorationhandler: ([Anyobject]?) , Void)Bool {if#available (IOS9.0, *) { ifUseractivity.activitytype = =Cssearchableitemactiontype {ifLet uniqueidentifier = Useractivity.userinfo? [Cssearchableitemactivityidentifier] as? String, let label =Useractivity.title {//page Jump } } } return true }
Second, additional experience
2.1 Cssearchableitemattributeset
You can not set the Thumbnaildata, so that the default is the current application of the LOGO, but also note that Thumbnailurl is not used to specify the network image address-#, so you need to add thumbnails to the online download to the local re-set
2.2 Cssearchableitem
Default is one months, also found unable to carry more data (such as through the cssearchableitemattributeset of the SetValue, on the side of the useractivity can not receive)
2.3 No limit on number of index bars found
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 suitable for batch processing.
2.4 No way to find re-indexing
Repeated calls are no problem, as long as the uniqueidentifier match overwrites the old data
2.5 didn't find a way to raise the rankings
It seems that the system has a set of algorithms to automatically increase rankings.
"Swift" IOS 9 Core Spotlight