【发布时间】:2016-04-06 04:02:12
【问题描述】:
知道为什么有些CNContacts 会返回 EMPTY 电话号码吗?
我不断得到这样的输出:
"phoneNumbers=(not fetched), emailAddresses=(not fetched),"
例如,当我从模拟器的内置联系人应用程序中获取联系人时,我得到了不同的结果:
"John Appleseed"确实返回了它的电话号码,但"Kate Bell"没有 - 尽管她显然已经电话号码。
这很奇怪,因为我肯定在我的 fetch 请求中使用了CNContactPhoneNumbersKey。
这是我的代码:
let fetchKeys = [ CNContactEmailAddressesKey, CNContactPhoneNumbersKey,
CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName) ]
let contactFetchRequest = CNContactFetchRequest(keysToFetch: fetchKeys)
do {
try self.contactsStore.enumerateContactsWithFetchRequest(contactFetchRequest) {
fetchedContact, stop in
print("fetched Contact is: \n\(fetchedContact.description)")
}
}
正如我所提到的,输出显示有时获取的联系人会返回电话号码,但有时不会。电子邮件也一样:有时会被退回,有时不会。
在模拟器中以及在我的 iPhone 上运行时都会发生这种情况。
知道这里会发生什么吗?
【问题讨论】:
-
这可能会帮助您在 fetchKeys
CNContactViewController.descriptorForRequiredKeys中添加一个 ket -
我在尝试检查是否 ([person.emailAddresses count] > 0) 时崩溃了
标签: ios swift ios9 cncontact cncontactstore