【发布时间】:2015-10-14 01:36:59
【问题描述】:
我的应用程序使用放入 PFTableViewController 的 Parse Objects。该应用程序的用户可以添加新内容,并且对于使用该应用程序的每个其他人来说,这将显示为一个新单元格。我想在此实现 iOS 9 的 Core Spotlight 功能,以便当用户打开应用程序时,它会索引来自 PFObjects 的数据。例如,应用程序(祈祷应用程序)中的用户说他们需要为成为酒鬼而祈祷……其他人可以在电话上转到 Spotlight 搜索,输入酒鬼,然后会显示该特定请求。我在 App Search Programming Guide 中看到的类似这样的例子是用 Swift 编写的,而我在 Obj-C 中更舒服,并且不想仅仅为了这个而将这个应用程序的整个类重写为 Swift特征。它也适用于一次性使用的项目,有人可以帮助指导我转换为 Obj-C 以及如何让它一次索引所有 20 个可见的,并在它们向下翻页时继续索引?
// Create an attribute set to describe an item.
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeData as String)
// Add metadata that supplies details about the item.
attributeSet.title = "July Report.Numbers"
attributeSet.contentDescription = "iWork Numbers Document"
attributeSet.thumbnailData = DocumentImage.jpg
// Create an item with a unique identifier, a domain identifier, and the attribute set you created earlier.
let item = CSSearchableItem(uniqueIdentifier: "1", domainIdentifier: "file-1", attributeSet: attributeSet)
// Add the item to the on-device index.
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([item]) { error in
if error != nil {
print(error?.localizedDescription)
}
else {
print("Item indexed.")
}
}
【问题讨论】:
标签: ios search ios9 corespotlight