ios - CSSearchableAttributeset 支持PhoneCall、Navigation 不起作用

标签 ios swift spotlight corespotlight

我正在尝试在 Spotlight 上公开我的应用

基本信息现已公开,但电话和导航无法使用

这是我的代码

    var searchableItems = [CSSearchableItem]()

    let hospitals = contents.compactMap { $0 as? Hospital }
    for hospital in hospitals {
        let searchItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeData as String)
        searchItemAttributeSet.title = hospital.name
        searchItemAttributeSet.contentDescription = "visited"
        searchItemAttributeSet.phoneNumbers = ["00-0000-0000"]
        searchItemAttributeSet.latitude = NSNumber(value: hospital.coordinate.latitude)
        searchItemAttributeSet.longitude = NSNumber(value: hospital.coordinate.longitude)
        searchItemAttributeSet.supportsPhoneCall = 1
        searchItemAttributeSet.supportsNavigation = 1
        let searchableItem = CSSearchableItem(uniqueIdentifier: "\(hospital.identifier)", domainIdentifier: "hospitals", attributeSet: searchItemAttributeSet)
        searchableItems.append(searchableItem)
    }

    CSSearchableIndex.default().indexSearchableItems(searchableItems) { (error) -> Void in
        if error != nil {
            print(error?.localizedDescription ?? "Error")
        }
    }

在 Spotlight 上搜索时,有标题和内容描述,但没有电话调用按钮和导航按钮

如何将它们添加到结果中

最佳答案

您需要将属性设置为true,而不是1

for hospital in hospitals {
    let searchItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeData as String)
    searchItemAttributeSet.title = hospital.name
    searchItemAttributeSet.contentDescription = "visited"
    searchItemAttributeSet.phoneNumbers = ["00-0000-0000"]
    searchItemAttributeSet.latitude = NSNumber(value: hospital.coordinate.latitude)
    searchItemAttributeSet.longitude = NSNumber(value: hospital.coordinate.longitude)
    searchItemAttributeSet.supportsPhoneCall = true
    searchItemAttributeSet.supportsNavigation = true
    let searchableItem = CSSearchableItem(uniqueIdentifier: "\(hospital.identifier)", domainIdentifier: "hospitals", attributeSet: searchItemAttributeSet)
    searchableItems.append(searchableItem)
}

关于ios - CSSearchableAttributeset 支持PhoneCall、Navigation 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55584207/

相关文章:

ios - 如何快速获取json对象的数组

ios - 按下按钮时应用程序卡住

macos - 如何对 NSMetadataQuery 的结果进行分组

macos - 获取包内文件的 kMDItemKind 返回 nil

ios - 在 UIScrollView 中自动调整 UITextView 的大小

ios - 应用更新后重新显示推送通知弹出窗口

xcode - swift 泛型 : More specialized than generic?

ios - CoreSpotlight 框架与 Spotlight 索引扩展?

ios - 有没有办法以编程方式检测 iOS 9 低功耗模式?

ios - 遍历 TableView 单元格?