CSSearchableAttributeset supportPhoneCall,导航不工作
CSSearchableAttributeset supportPhoneCall, Navigation are not working
我正在尝试在 Spotlight 上公开我的应用程序
基本信息现已公开,但 phone 呼叫和导航无法正常工作
下面是我的代码
var searchableItems = [CSSearchableItem]()
let hospitals = contents.compactMap { [=10=] 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 上搜索时有 title 和 contentDescription 但没有 phoneCall Button 和 navigation Button
如何将它们添加到结果中
您可以尝试设置要搜索的关键字。
例如 searchItemAttributeSet.keywords = ["xxx", "xxx"];
您需要将属性设置为 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)
}
我正在尝试在 Spotlight 上公开我的应用程序
基本信息现已公开,但 phone 呼叫和导航无法正常工作
下面是我的代码
var searchableItems = [CSSearchableItem]()
let hospitals = contents.compactMap { [=10=] 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 上搜索时有 title 和 contentDescription 但没有 phoneCall Button 和 navigation Button
如何将它们添加到结果中
您可以尝试设置要搜索的关键字。 例如 searchItemAttributeSet.keywords = ["xxx", "xxx"];
您需要将属性设置为 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)
}