我正在使用 try contactStore.unifiedContactsMatchingPredicate
和键 CNContactPhoneNumbersKey
但我不确定要使用什么 NSPredicate
来简单地接受所有具有非零 CNContactPhoneNumbersKey
的 CNContact
。
最佳答案
您必须枚举整个联系人存储,因为谓词还不够灵活:
var contactsWithPhoneNumber = [CNContact]()
let fetchRequest = CNContactFetchRequest(keysToFetch: [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey])
try! contactStore.enumerateContactsWithFetchRequest(fetchRequest) { contact, stop in
if contact.phoneNumbers.count > 0 {
contactsWithPhoneNumbers.append(contact)
}
}
关于ios - 如何使用 Swift 中的联系人框架获取手机号码的所有联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37449730/