IOS 9 Core Spotlight Search Instance Code _ios

Source: Internet
Author: User

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.

Related Article

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.