"Swift" IOS 9 Core Spotlight

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.