ios - CoreSpotlight 索引不起作用

标签 ios swift search ios9 corespotlight

我正在使用 CoreSpotLight api 来索引一些内容。出于某种原因,我在搜索时找不到数据 聚光灯。

let atset:CSSearchableItemAttributeSet = CSSearchableItemAttributeSet()  
atset.title = "Simple title"  
atset.contentDescription = "Simple twitter search"  
let item = CSSearchableItem(uniqueIdentifier: "id1", domainIdentifier: "com.shrikar.twitter.search", attributeSet: atset)  
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([item]) { (error) -> Void in  
 print("Indexed")  
}  

当我运行该应用程序时,我看到数据已编入索引并且错误为零。 此外,我还在构建阶段添加了 CoreSpotLight 和 MobileCoreServices。

最佳答案

尝试像这样使用 itemContentType 初始化程序:

let atset:CSSearchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)
atset.title = "Simple title"
atset.contentDescription = "Simple twitter search"
let item = CSSearchableItem(uniqueIdentifier: "id1", domainIdentifier: "com.shrikar.twitter.search", attributeSet: atset)
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([item]) { (error) -> Void in
    print("Indexed")  
}

kUTTypeImageMobileCoreServices 中声明。

关于ios - CoreSpotlight 索引不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30826500/

相关文章:

ios - iOS 表/ Collection View 中的单元格间布局逻辑

macos - 了解枚举和函数签名

Swift 解析进度 block : extra argument in call

ios - getter 和 setter 自定义并发队列同步的竞争条件

Android - 为 RecyclerView 实现搜索过滤器

search - LaTeX:如何查找命令所属的包?

java - 进行更好的搜索而不出现滞后

ios - socket编程中如何发送结构体数据?

ios - 在 iOS OpenGL ES 上渲染到纹理——适用于模拟器,但不适用于设备

ios - 如何像 Facebook 一样向下滚动后从顶部滚动 - Swift 4.2