Code needs to run on iOS9 or later
Need to increase the system version of the judgment
#pragma mark - searchable search + (void) addsearchableitem{ cssearchableitemattributeset *attributeset = [[cssearchableitemattributeset alloc] initwithitemcontenttype:@ "Duwu. Topic.test "]; attributeset.title = @" title "; attributeset.contentdescription = @ "content"; //tried to pass the URL in seems to be a picture that does not show the network / attributeset.thumbnailurl = [nsurl urlwithstring:@ "ImageURL"]; attributeset.keywords = @[@ "Can", @ "Add", @ "multiple", @ "keywords"]; //because I have no local image to display and add to searchable search as if not much real-time I took a sub-thread to download pictures and other images downloaded in the Add to the search bar method dispatch_async (Dispatch_get_global_queue (0, 0), ^{ nsdata *_thumbnaildata = [[nsdata alloc] initwithcontentsofurl:attributeset.thumbnailurl]; attributeSet.thumbnailData = _thumbnailData; cssearchableitem *_item = [[ cssearchableitem alloc] initwithuniqueidentifier:@ "A special ID that makes it easy for users to click into the app and treat it differently" domainidentifier:@ "Group Info" attributeSet:attributeSet]; //Delete a grouped searchable search [[ cssearchableindex defaultsearchableindex] deletesearchableitemswithdomainidentifiers:@[@ "group Information"] completionhandler:^ (Nserror * _nullable error) { }]; //add information to searchable search &nbsP; [[cssearchableindex defaultsearchableindex] indexsearchableitems:@[_item] completionhandler:^ (Nserror * _nullable error) { }]; }); }
This article is from the "Low profile" blog, please be sure to keep this source http://liyun2422.blog.51cto.com/9161506/1732212
IOS9 new features searchable search