iOS 6地址簿空kABPersonPhoneProperty [英] iOS 6 address book empty kABPersonPhoneProperty

查看:83
本文介绍了iOS 6地址簿空kABPersonPhoneProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my code I use ABPeoplePickerNavigationController to select person. After user select person from contact list, I look if specified person record have any phone number:

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

我创建了联系人,为其添加了电话号码并测试了我的代码。在iOS 5中,此代码运行良好。 手机变量包含一个电话号码。

I created contact, added phone number to it and tested my code. In iOS 5 this code works well. phones variable contains one phone number.

但在iOS 6中,将联系人链接到Facebook帐户后,手机变量不包含任何值。

But in iOS 6, after linking contact to facebook account, phones variable doesn't contain any values.

取消与Facebook帐户的联系后,一切运作良好。

After unlinking contact with facebook account everything works well again.

如何通过此方法阅读人员电话号码?

How can I read person phone numbers this method?

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

UPD

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

If i return YES in the function above, then in function

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

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

I can read all person phone numbers in normal way. So why I can't read them in the first function?

推荐答案

我找到了问题的答案。
如果联系人是链接的,那么在方法

I found the answer to my question. If the contact is linked, then in method

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

您收到对person的引用,该引用表示已链接的联系人。要检索所有电话号码,您需要获取所有链接的联系人,然后在该联系人中查找电话号码。
我使用以下代码执行此操作:

you recieve a reference to person, which respesents a linked contact. To retrieve all phone numbers you need to get all linked contacts and then look for phone numbers in that contacts. I do this with the following code:

- (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 ...

}

使用该代码我收到了链接联系人的所有电话号码。

With that code i received all phone numbers for linked contact.

这篇关于iOS 6地址簿空kABPersonPhoneProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆