iphone – 从Facebook同步/“统一信息”地址簿联系人获取电话号码

我需要能够从用户的地址簿中读取联系人的电话号码.问题是,如果用户选择通过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);
,但这也没有返回任何内容:[第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用户&得到他们的电话信息?

最佳答案 来自Apple支持:

We do not have any APIs that will return a unified Address Book
contact. However, you can retrieve phone numbers of contacts that
appear as unified in Contacts on your device by first using
ABPersonCopyArrayOfAllLinkedPeople to retrieve all linked contacts,
then iterating through these contacts to fetch their respective phone
numbers. Note that phone numbers that do not appear in the UI in
Contacts will not be returned by Address Book APIs. See below for a
snippet of code that will allow you to do so:

- (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;
点赞