我需要能够从用户的通讯录中读取联系人的电话号码。问题在于,如果用户选择通过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用户并获取他们的电话信息,那我该怎么知道呢?