iOS 6地址簿空kABPersonPhoneProperty

在我的代码中,我使用ABPeoplePickerNavigationController来select人员。 用户从联系人列表中select人员后,我查看指定的人员logging是否有任何电话号码:

- (BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { ABMutableMultiValueRef phones; phones = ABRecordCopyValue(person, kABPersonPhoneProperty); if (phones == nil || ABMultiValueGetCount(phones) == 0) { return NO; } // other code.... } 

我创build了联系人,添加了电话号码并testing了我的代码。 在iOS 5中,此代码运行良好。 手机variables包含一个电话号码。

但在iOS 6中,将联系人链接到Facebook帐户后, 电话variables不包含任何值。

解除与facebook帐户的联系后,一切运作良好。

我怎样才能读取这个方法的人电话号码?

 - (BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person 

UPD

如果我在上面的函数中返回YES,那么在函数中

  (BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier 

我可以正常阅读所有人的电话号码。 那么为什么我不能在第一个函数中读取它们呢?

我find了我的问题的答案。 如果联系人被链接,则在方法中

 - (BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person 

你会收到一个人的参考,这个参考是一个链接的联系人。 要检索所有电话号码,您需要获取所有链接的联系人,然后在该联系人中查找电话号码。 我用下面的代码来做到这一点:

 - (BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { ABMutableMultiValueRef phones; phones = ABRecordCopyValue(person, kABPersonPhoneProperty); if (phones == nil || ABMultiValueGetCount(phones) == 0) { CFArrayRef linkedContacts = ABPersonCopyArrayOfAllLinkedPeople(person); phones = ABMultiValueCreateMutable(kABPersonPhoneProperty); ABMultiValueRef linkedPhones; for (int i = 0; i < CFArrayGetCount(linkedContacts); i++) { ABRecordRef linkedContact = CFArrayGetValueAtIndex(linkedContacts, i); linkedPhones = ABRecordCopyValue(linkedContact, kABPersonPhoneProperty); if (linkedPhones != nil && ABMultiValueGetCount(linkedPhones) > 0) { for (int j = 0; j < ABMultiValueGetCount(linkedPhones); j++) { ABMultiValueAddValueAndLabel(phones, ABMultiValueCopyValueAtIndex(linkedPhones, j), NULL, NULL); } } CFRelease(linkedPhones); } CFRelease(linkedContacts); if (ABMultiValueGetCount(phones) == 0) { CFRelease(phones); return NO; } } // other code ... } 

有了这个代码,我收到了联系联系人的所有电话号码。

在解决scheme:链接的联系人,你需要改变存储发现电话号码的行

 ABMultiValueAddValueAndLabel(phones, ABMultiValueCopyValueAtIndex(linkedPhones, j), ABMultiValueCopyLabelAtIndex(linkedPhones, j), NULL); 

以便您可以稍后使用“手机”进行标签检查。 给出的解决scheme只是存储的数字,所以你将无法testing像常量,如kABPersonPhoneMainLabel

这种方法也用于电子邮件和地址。 对于地址你拿出这样的部分:

 CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(address, 0); street.text = CFBridgingRelease(CFDictionaryGetValue(dict, kABPersonAddressStreetKey));