从与Facebook同步的“统一信息”通讯录联系人中获取电话号码

4

我需要能够从用户的通讯录中读取联系人的电话号码。问题在于,如果用户选择通过Facebook同步这些联系人,则无法通过以下代码访问它们(对于未同步的联系人确实有效):

ABMultiValueRef phones = ABRecordCopyValue(record, kABPersonPhoneProperty);
DLog(@"Found %ld phones", ABMultiValueGetCount(phones));
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{        
    CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
    CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(phones, j);
    NSString *phoneLabel =(__bridge NSString*) ABAddressBookCopyLocalizedLabel(locLabel);
    NSString *phoneNumber = (__bridge NSString *)phoneNumberRef;
    CFRelease(phoneNumberRef);
    CFRelease(locLabel);
    DLog(@"  - %@ (%@)", phoneNumber, phoneLabel);
    [numbersArr addObject:phoneNumber];
}

日志结果为:[Line 126] 找到0个电话

我尝试使用CFArrayRef userNumbers = ABMultiValueCopyArrayOfAllValues(phoneNumbers);
,但这也什么都没返回:[Line 118] 获取用户号码:(null)

所以我尝试深入社交资料,但这还是什么都没返回!

// Try to get phone numbers from social profile
        ABMultiValueRef profiles = ABRecordCopyValue(record, kABPersonSocialProfileProperty);
        CFIndex multiCount = ABMultiValueGetCount(profiles);
        for (CFIndex i=0; i<multiCount; i++) {
            NSDictionary* profile = (__bridge NSDictionary*)ABMultiValueCopyValueAtIndex(profiles, i);
            NSLog(@"TESTING - Profile: %@", profile);

        }
        DLog(@"Got profiles: %@", profiles);
        CFRelease(profiles);

然而,日志记录如下:

[第161行] 收到的配置文件:ABMultiValueRef 0x1ddbb5c0,共有0个值

如果上述结果都没有帮助我找到Facebook用户并获取他们的电话信息,那我该怎么知道呢?

1个回答

2

来自苹果支持:

我们没有任何API可以返回统一的通讯录联系人,但是,您可以通过首先使用ABPersonCopyArrayOfAllLinkedPeople检索所有链接联系人,然后迭代这些联系人以获取它们各自的电话号码,从而检索出在您的设备上在联系人中显示为统一的联系人的电话号码。请注意,不在联系人界面中显示的电话号码将不会被Address Book API返回。以下是一个代码片段,可帮助您完成此操作:

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

{

//Fetch all linked contacts

CFArrayRef linkedPerson = ABPersonCopyArrayOfAllLinkedPeople(person);

//Iterate through each linked contact to fetch the phone numbers

for (CFIndex i = 0; i < CFArrayGetCount(linkedPerson); i++)

{

ABRecordRef contact = CFArrayGetValueAtIndex(linkedPerson,i);

ABMutableMultiValueRef multi = ABRecordCopyValue(contact, kABPersonPhoneProperty);

for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++)

{

CFStringRef label = ABMultiValueCopyLabelAtIndex(multi, i);

CFStringRef number = ABMultiValueCopyValueAtIndex(multi, i);

CFRelease(label);

CFRelease(number);

}

CFRelease(multi);

}

CFRelease(linkedPerson);

return YES;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接