【发布时间】:2012-06-28 03:48:08
【问题描述】:
我正在尝试从通讯录中的联系人获取 Twitter 用户名,但我做不到
我正在使用我发现“谷歌搜索”的这段代码:
- (NSString*)getTwitterUsernameFromRecord:(ABRecordRef)record {
NSString * twitterUsername = nil;
ABMultiValueRef socials = ABRecordCopyValue(record, kABPersonSocialProfileProperty);
if (!socials) {
return nil;
}
CFIndex socialsCount = ABMultiValueGetCount(socials);
for (int k=0 ; k<socialsCount ; k++) {
CFDictionaryRef socialValue = ABMultiValueCopyValueAtIndex(socials, k);
if(CFStringCompare( CFDictionaryGetValue(socialValue, kABPersonSocialProfileServiceKey), kABPersonSocialProfileServiceTwitter, 0)==kCFCompareEqualTo) {
twitterUsername = (NSString*) CFDictionaryGetValue(socialValue, kABPersonSocialProfileUsernameKey);
}
CFRelease(socialValue);
if(twitterUsername)
break;
}
CFRelease(socials);
return twitterUsername;
}
我使用 if 来验证“socials”数组是否为零,因为在尝试获取“socials”数组计数时遇到异常。
我已经在模拟器和带有联系人的真实设备中尝试了此代码,其中填充了 twitter 信息,但我得到的“社交”数组始终为零。我从记录中得到了错误的财产?有什么帮助吗?
提前谢谢你
【问题讨论】:
标签: iphone objective-c twitter abaddressbook