我需要能够从用户的通讯录中读取联系人的电话号码。问题是,如果用户选择通过 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] Found 0 phones
我曾尝试使用CFArrayRef userNumbers = ABMultiValueCopyArrayOfAllValues(phoneNumbers);
,但这也没有返回任何内容:[Line 118] Got user numbers: (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);
然而日志条目是:
[Line 161] Got profiles: ABMultiValueRef 0x1ddbb5c0 with 0 value(s)
如果上述结果都没有给我任何帮助,我怎么知道他们是 Facebook 用户并获取他们的电话信息?