溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

IOS9新特性 Searchable搜索

發(fā)布時(shí)間:2020-06-30 13:05:01 來(lái)源:網(wǎng)絡(luò) 閱讀:2313 作者:liyun2422 欄目:移動(dòng)開(kāi)發(fā)

代碼需要運(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)重降低的...

向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI