ABMultiValueGetCount - kABPersonSocialProfileProperty 总是返回 0 吗?如何从通讯录中获取 Facebook 详细信息?

Posted

技术标签:

【中文标题】ABMultiValueGetCount - kABPersonSocialProfileProperty 总是返回 0 吗?如何从通讯录中获取 Facebook 详细信息?【英文标题】:ABMultiValueGetCount - kABPersonSocialProfileProperty always returns 0 ? How can I get Facebook details from address book? 【发布时间】:2013-04-08 02:29:31 【问题描述】:

您好,谁能告诉我为什么 ABMultiValueGetCount(social) 总是返回 0 count ?所有其他字段完美地从地址簿返回。

我正在尝试查看联系人是否激活了 Twitter 或 Facebook?我的用户在 AB 中定义了 Twitter 和 Facebook。我可以在那里看到他们!

/* The table view controller ViewDidLoad opened the AddressBook and copied these details into addressBookArray then I closed the reference to the AddressBook */
ABRecordRef person = (__bridge ABRecordRef)[addressBookArray objectAtIndex:indexPath.section];

/*  Make sure AddressBook is currently open so we can look at things */
ABAddressBookRef addressBook;
addressBook = ABAddressBookCreateWithOptions(NULL, NULL);

if (addressBook != NULL)

    NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

    /* If I don't do this person always returns NULL for social */
    ABRecordRef who = ABRecordCopyValue(ABAddressBookGetPersonWithRecordID (addressBook, ABRecordGetRecordID(person));

    /* ABMultiValueRef social = ABRecordCopyValue(person, kABPersonSocialProfileProperty); - always returns NULL */
    ABMultiValueRef social = ABRecordCopyValue(who, kABPersonSocialProfileProperty); // always returns a value

    /* C is always 0 even if user has FB/Twitter etc why ? */
    CFIndex c = ABMultiValueGetCount(social);

    CFRelease (addressBook);

我已经阅读了这个问题:

ABRecordCopyValue return 0 ?

但是,如果我编辑 AB 联系人并实际添加 twitter,我仍然没有得到结果。还有另一种解决方法吗?显然,Apple 会这样做,就像联系人应用程序告诉你的那样。

【问题讨论】:

这很不直观,但原因是“在用户将 FaceBook 联系人与本机联系人联系起来之前,该方法永远不会起作用”参见***.com/a/14733022/645314。 【参考方案1】:

好的,取得了一些进展......

似乎此属性确实有效 kABPersonInstantMessageProperty。

分享我到目前为止所做的事情,因为这似乎难倒了很多用户。至少此代码可以用作查看您是否拥有 Skype、Yahoo、Facebook 等的基础......但我想获得 FBID,并且它保存在 kABPersonSocialProfileProperty 下。为什么 kABPersonSocialProfileProperty 不如 kABPersonInstantMessageProperty 工作?是 ios 6 的问题吗....

*不,除非您在 iOS 设备上手动转到设置 - Facebook - 更新所有联系人,否则地址簿似乎不知道 kABPersonSocialProfileProperty。为什么苹果与这两个属性不一致?此外,您必须选择作为主要联系人创建的链接联系人也不包含这些详细信息!*

另外,为什么我必须分配“谁”而不能原生使用“人”?

还有其他人有更多的想法吗?

/*  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]);
        

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

        howManySocialApps += thisSocialAppCount;
    

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

    CFRelease(addressBook);

【讨论】:

以上是关于ABMultiValueGetCount - kABPersonSocialProfileProperty 总是返回 0 吗?如何从通讯录中获取 Facebook 详细信息?的主要内容,如果未能解决你的问题,请参考以下文章

ABMultiValueCopyValueAtIndex 允许发布两次?

如何根据R中的最后一行在所选行中添加前缀

使用android对sqlite中的字母数字值进行自然排序

csharp Kağıttaşmakasoyunu

P6818 [PA2013]Działka 题解

LabVIEW仪器控制:智能直流电源(科睿源KA3003)