【发布时间】:2015-09-21 12:12:16
【问题描述】:
在 ios 8 中,我使用以下代码打印用户的联系电话,
if let contacts = ABAddressBookCopyArrayOfAllPeople(self.addressBookRef)?.takeRetainedValue() as? NSArray {
for record:ABRecordRef in contacts {
let phones:ABMultiValueRef = ABRecordCopyValue(record, kABPersonPhoneProperty).takeUnretainedValue() as ABMultiValueRef
for(var numberIndex : CFIndex = 0; numberIndex < ABMultiValueGetCount(phones); numberIndex++)
{
let phoneUnmaganed = ABMultiValueCopyValueAtIndex(phones, numberIndex)
let phoneNumber : String = phoneUnmaganed.takeUnretainedValue() as! String
println(电话号码) } }
但苹果在 ios 9 中引入了新的联系人框架。现在我坚持检索联系人号码。我在苹果网站和其他网站中找到了一些代码,如下所示,但它仍然不完全只打印联系号码,
contacts = try store.unifiedContactsMatchingPredicate(
CNContact.predicateForContactsMatchingName("Siva"),
keysToFetch:[CNContactPhoneNumbersKey])
for contact:CNContact in contacts {
if (contact.isKeyAvailable(CNContactPhoneNumbersKey)) {
for phoneNumber:CNLabeledValue in contact.phoneNumbers {
print(phoneNumber.value)
}
}
【问题讨论】:
-
请帮我找回所有的联系电话,