"iOS Tools Class" IOS9 corespotlight (OC language)

Source: Internet
Author: User

What is Corespotlight? Just under IOS9, let the user search for your app in the dropdown search page.

#import <Foundation/Foundation.h> @interface ios9searchapiutil:nsobject+ (ios9searchapiutil *) sharedinstance ;-(void) Addsearchitemsarray: (Nsarray *) array; @end

#import "IOS9SearchAPIUtil.h" #import <CoreSpotlight/CoreSpotlight.h> #import <mobilecoreservices/ mobilecoreservices.h> #import "Nsstring+wrapper.h" #import <UIKit/UIKit.h> #define Ios9searchapiutil_    Domainidentifier @ "Com.searchapi.shows" @implementation ios9searchapiutil+ (Ios9searchapiutil *) sharedinstance{    static Ios9searchapiutil *instance = nil;    static dispatch_once_t predicate;    Dispatch_once (&predicate, ^{instance = [[Self alloc] init];    }); return instance;} -(void) Addsearchitemsarray: (Nsarray *) array{if (is_ios_9) {Nsmutablearray <cssearchableitem *> *searchable        Items = [Nsmutablearray arraywithcapacity:0];            For (nsdictionary *d in array) {NSString *title = [D objectforkey:@ "title"];            NSString *desc = [D objectforkey:@ "desc"];            NSString *time = [D objectforkey:@ "Time"];            NSString *nid = [D objectforkey:@ "nid"]; Cssearchableitemattributeset *attributeset = [[cssearchableItemattributeset alloc]initwithitemcontenttype:@ "Searchapiviews"];            Attributeset.title = title;            Attributeset.contentdescription = [NSString stringwithformat:@ "%@\n%@", Desc,time];            Nsmutablearray *keywords = [Nsmutablearray arraywitharray:[title split:@ ""]];            [keywords Addobject:desc];            attributeset.keywords = keywords;            NSString *identifiner = [NSString stringwithformat:@ "%@", nid]; [Searchableitems Addobject:[[cssearchableitem Alloc]initwithuniqueidentifier:identifiner DomainIdentifier:I        Os9searchapiutil_domainidentifier Attributeset:attributeset]]; } [[Cssearchableindex Defaultsearchableindex]indexsearchableitems:searchableitems completionHandler:^ (NSErr            or * __nullable error) {if (Error! = nil) {NSLog (@ "%@", error.localizeddescription);            }else {NSLog (@ "Items were indexed successfully");    }        }]; }} @end
How to use:
[[Ios9searchapiutil sharedinstance]addsearchitemsarray:@[@{@ "nid": @ "fin://1238796", @ "title": @ "Fin", @ "desc": @ "fund @ "Time": @ "2014-01-01"},@{@ "nid": @ "Fun://54fdsaf32", @ "title": @ "Fun" @ "desc": @ "Money" @ "time": @ "2016-01-01"}];
Effect:



Ps:

Upload framework:



Swift version: Http://www.csdn.net/article/2015-07-16/2825222-search-apis


#define IS_IOS_9 ([[[Uidevice Currentdevice] systemversion] floatvalue] >=9.0 ? Yes:no)

Split is the Componentsseparatedbystring method of calling NSString;

Nsstring+wapper.h class Reference: http://blog.csdn.net/coooliang/article/details/45871149



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"iOS Tools Class" IOS9 corespotlight (OC language)

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.