我正在使用 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")
}
kUTTypeImage
在 MobileCoreServices
中声明。
关于ios - CoreSpotlight 索引不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30826500/