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;

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...