gpt4 book ai didi

ios - 无法从 iOS6 中的 ABAddressBook 获取 Facebook 配置文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:22:58 25 4
gpt4 key购买 nike

我正在使用以下代码从 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 个人资料,但情况仍然如此。

有什么想法吗?

最佳答案

嗨,我想我已经解决了这个转到我自己回答的问题:

ABMultiValueGetCount - kABPersonSocialProfileProperty always returns 0 ? How can I get Facebook details from address book?

这可能是由于用户必须通过 iOS 上的按钮手动更新 facebook 或记录没有出现。我被困在眼前的事实中,我可以在地址簿中看到 facebook 联系人,但社会属性(property)给了我 nada !一旦我更新并扫描了链接的联系人,我就找到了我需要的一切。还包括我的代码:

/*  person is of type ABRecordRef loaded from an array thus:
addressBookArray = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
.....
person = (__bridge ABRecordRef)[addressBookArray objectAtIndex:indexPath.section];
*/


ABAddressBookRef addressBook;
addressBook = ABAddressBookCreateWithOptions(NULL, NULL);

if (addressBook != Nil)
{
int howManySocialApps;
ABRecordRef who = ABAddressBookGetPersonWithRecordID (addressBook, ABRecordGetRecordID(person));

NSArray *linkedPeople = (__bridge_transfer NSArray *)ABPersonCopyArrayOfAllLinkedPeople (who);

for (int x = 0; x < [linkedPeople count]; x++)
{
ABMultiValueRef socialApps = ABRecordCopyValue((__bridge ABRecordRef)[linkedPeople objectAtIndex:x], kABPersonSocialProfileProperty);

CFIndex thisSocialAppCount = ABMultiValueGetCount(socialApps);

for (int i = 0; i < thisSocialAppCount; i++)
{
NSDictionary *socialItem = (__bridge_transfer NSDictionary*)ABMultiValueCopyValueAtIndex(socialApps, i);
NSLog(@"Social Item of type %@", [socialItem objectForKey:(NSString *)kABPersonSocialProfileServiceKey]);
/* put tests for facebook etc here */
}

if (socialApps != Nil)
CFRelease(socialApps);

howManySocialApps += thisSocialAppCount;
}

NSLog (@"Number of SocialApps Found is %i", howManySocialApps);

CFRelease(addressBook);
}

我发现另一件有用的事情是确保我被操纵的数组没有很多重复的联系人,即 FB、Twitter 等的入口用户。Apple 有一些很好的代码可以做到这一点:

    ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
addressBookArray = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByLastName);

然后使用链接的联系人我们可以找到任何东西。

干杯。

关于ios - 无法从 iOS6 中的 ABAddressBook 获取 Facebook 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14507638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com