问题描述
你们可以告诉我为什么ABMultiValueGetCount(社交)总是返回0计数吗?所有其他字段完全从地址簿返回。
Hi can anyone tell me why ABMultiValueGetCount(social) always returns 0 count ? All other fields return from the address book perfectly.
我正试图看看联系人是否有Twitter或Facebook活跃?我的用户在AB中定义了Twitter和Facebook。我可以在那里看到它们!!
I'm trying to see if contact has Twitter or Facebook active ? My users have Twitter and Facebook defined in the AB. I can see them there !!
/* 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);
}
我读过这个问题:
但是,如果我编辑AB联系并实际添加推特我仍然没有得到结果。有没有其他方法解决这个问题?显然苹果做了,作为联系人应用程序告诉你它。
However, if I edit an AB Contact and actually add twitter I still don't get a result. Is there another way of working this out ? Obviously Apple do it, as the Contacts App tells you about it.
推荐答案
好的,取得了一些进展....
Alright, made some progress ....
似乎这个属性确实有效kABPersonInstantMessageProperty。
Seems this property does work kABPersonInstantMessageProperty.
分享到目前为止我所做的事情,因为这似乎让很多用户感到困惑。至少这个代码可以作为一个基础,看看你是否有Skype,雅虎,Facebook等.....但我想获得FBID,并在kABPersonSocialProfileProperty下保存。为什么kABPersonSocialProfileProperty和kABPersonInstantMessageProperty一样无效?这是iOS 6问题....
Sharing what I've done so far, as this seems to stump so many users. At least this code can be used as a basis to see if you have Skype, Yahoo, Facebook etc ..... but I want to get the FBID and that's held under kABPersonSocialProfileProperty. Why doesn't kABPersonSocialProfileProperty work as well as kABPersonInstantMessageProperty ? Is it an iOS 6 issue ....
* 除非您手动转到设置 - Facebook - 更新您的所有联系人iOS设备,AddressBook不知道kABPersonSocialProfileProperty。为什么Apple与这两个属性不一致?此外,您必须选择创建的链接联系人,因为主要联系人也不会保留这些详细信息!! *
*No it appears that unless you manually go to Settings - Facebook - Update All Contacts on your iOS device, the AddressBook has no knowledge for kABPersonSocialProfileProperty. Why is Apple inconsistent with the two properties ? In addition you have to select the linked contact that was created as the main contact also does not hold these details !!*
此外,为什么我必须指定'谁'而不能本地使用'人'?
Also, why do I have to assign 'who' and can't use 'person' natively ?
还有其他人有更多想法吗?
Any one else got any more ideas ?
/* 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详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!