gpt4 book ai didi

swift2 - 如何在ios 9中检索联系电话

转载 作者:行者123 更新时间:2023-12-04 13:08:01 28 4
gpt4 key购买 nike

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

最佳答案

这应该这样做。

        if (contact.isKeyAvailable(CNContactPhoneNumbersKey)) {
for phoneNumber:CNLabeledValue in contact.phoneNumbers {
let a = phoneNumber.value as! CNPhoneNumber
print("\(a.stringValue)")
}
}

打印的风格
(555) 766-4823

关于swift2 - 如何在ios 9中检索联系电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32694934/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com