我想获取存储的所有没有名字的联系人。以下方法帮助我搜索所有传递了字符串的联系人。我试图传递空字符串以找到没有名字的所有联系人,但它没有工作。
func fetchContactsWithNoName() {
let contactStore = CNContactStore()
// Get all the containers
var allContainers: [CNContainer] = []
do {
allContainers = try contactStore.containers(matching: nil)
} catch {
print("Error fetching containers")
}
// Iterate all containers and append their contacts to our results array
for _ in allContainers {
// let fetchPredicate = CNContact.predicateForContactsInContainer(withIdentifier: container.identifier)
do {
let containerResults = try contactStore.unifiedContacts(matching: CNContact.predicateForContacts(matchingName: " "), keysToFetch:[CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor])
self.results.append(contentsOf: containerResults)
} catch {
print("Error fetching results for container")
}
}
}