您好,登錄后才能下訂單哦!
代碼需要運(yùn)行在ios9或更高版本上
需要增加系統(tǒng)版本的判斷
#pragma mark - Searchable搜索 +(void)addSearchableItem{ CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:@"duwu.Topic.test"]; attributeSet.title = @"title"; attributeSet.contentDescription = @"content"; //試了一下傳URL進(jìn)去 好像是顯示不出網(wǎng)絡(luò)的圖片 // attributeSet.thumbnailURL = [NSURL URLWithString:@"p_w_picpathURL"]; attributeSet.keywords = @[@"可以",@"增加",@"多個(gè)",@"關(guān)鍵詞"]; //因?yàn)槲覜](méi)本地圖片去顯示 而且加到Searchable搜索里好像也不用多實(shí)時(shí) 我便采用了子線程下載圖片等圖片下載完了在增加到搜索欄里的方法 dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSData *_thumbnailData = [[NSData alloc] initWithContentsOfURL:attributeSet.thumbnailURL]; attributeSet.thumbnailData = _thumbnailData; CSSearchableItem *_item = [[CSSearchableItem alloc] initWithUniqueIdentifier:@"一個(gè)特殊的ID,便于用戶點(diǎn)擊進(jìn)入APP后區(qū)別處理" domainIdentifier:@"分組信息" attributeSet:attributeSet]; //刪除某個(gè)分組的Searchable搜索 [[CSSearchableIndex defaultSearchableIndex] deleteSearchableItemsWithDomainIdentifiers:@[@"分組信息"] completionHandler:^(NSError * _Nullable error) { }]; //增加信息到Searchable搜索 [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[_item] completionHandler:^(NSError * _Nullable error) { }]; }); }
最好也不要增加過(guò)多的關(guān)鍵詞和信息 濫用的話應(yīng)該會(huì)被系統(tǒng)把權(quán)重降低的...
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。