1

嗨,谁能告诉我为什么 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 返回 0 ?

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

4

1 回答 1

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);
}
于 2013-04-08T08:44:56.720 回答