I want my device to predict who is calling to me based on spotlight people index. I have uploaded people info to spotlight index and system gives info when I'm searching, but not when somebody is calling. The code below do all this stuff and I can't understand what's wrong
if people.count > 0 {
var peopleArray = [CSSearchableItem]()
var peopleGUIDs = [String]()
for person in people {
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String)
// Basic AttributeSet setup
attributeSet.title = person.nameForList
attributeSet.contentDescription = person.division?.title
// Add first phone number to AttributeSet
var phoneNumber: NSString?
let contacts = Array(person.contacts)
for contact in contacts {
if contact.type == "phone" {
phoneNumber = contact.value as NSString
break
}
}
if phoneNumber != nil {
if let preparedNumber = phoneNumber!.removingPercentEncoding {
attributeSet.phoneNumbers = [preparedNumber]
attributeSet.supportsPhoneCall = true
}
}
attributeSet.displayName = person.name
// Add photo number to AttributeSet
if let photoPath = person.photo {
let key = SDWebImageManager.shared().cacheKey(for: NSURL(string: photoPath) as URL!)
let image = SDImageCache.shared().imageFromDiskCache(forKey: key)
var data = Data()
if let image = image {
if let dataFromImage = UIImagePNGRepresentation(image) {
data = dataFromImage
}
} else {
data = dataFromImage
}
attributeSet.thumbnailData = data
}
peoplesGUIDs.append(person.id)
let item = CSSearchableItem(uniqueIdentifier: person.id, domainIdentifier: "com.it.companySpotlight", attributeSet: attributeSet)
peopleArray.append(item)
}
CSSearchableIndex.default().indexSearchableItems(peopleArray) { (error) in
DispatchQueue.main.async(execute: {
if let error = error {
print("Indexing error: \(error.localizedDescription)")
} else {
print("Search for people successfully indexed")
}
})
}
}
Does anybody know how to solve this problem?