使用Swift 3获取所有没有与之关联的名称的联系人

时间:2017-01-30 00:35:56

标签: ios swift cncontact cncontactstore

我想获取存储的所有没有名字的联系人。以下方法帮助我搜索所有传递了字符串的联系人。我试图传递空字符串以找到没有名字的所有联系人,但它没有工作。

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")
        }
    }

}

0 个答案:

没有答案