我正在使用以下代码从 iOS 6 中的通讯录中检索社交资料:
// get the address book
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(options, error);
// get all people
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
// get the number of people
CFIndex noOfPeople = ABAddressBookGetPersonCount(addressBook);
// for all people
for (CFIndex personIndex = 0; personIndex<noOfPeople; personIndex++)
{
// get social profiles
NSMutableArray *socialProfilesArray = [[NSMutableArray alloc] init];
ABMultiValueRef socialProfiles = ABRecordCopyValue(person, kABPersonSocialProfileProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(socialProfiles); j++)
{
NSDictionary* socialProfile = (NSDictionary*)ABMultiValueCopyValueAtIndex(socialProfiles, j);
if ([socialProfile[@"service"] isEqualToString:(NSString*)kABPersonSocialProfileServiceFacebook])
{
NSString *strFacebook = (NSString*)socialProfile[@"username"];
}
else if ([socialProfile[@"service"] isEqualToString:( NSString*)kABPersonSocialProfileServiceTwitter])
{
NSString *twitterName = (NSString*)socialProfile[@"username"];
}
[socialProfilesArray addObject:socialProfile];
[socialProfile release];
}
CFRelease(socialProfiles);
}
看来,虽然我成功获得了 Twitter 个人资料,但没有返回 Facebook 个人资料。尽管如联系人应用程序中所示,显然有一个 Facebook 个人资料与我的一个联系人相关联。
任何想法为什么?