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(phoneNumber的) } }
但苹果在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)
}
}
答案 0 :(得分:19)
这应该这样做。
if (contact.isKeyAvailable(CNContactPhoneNumbersKey)) {
for phoneNumber:CNLabeledValue in contact.phoneNumbers {
let a = phoneNumber.value as! CNPhoneNumber
print("\(a.stringValue)")
}
}
打印的风格 (555)766-4823