I'm trying to get the Twitter username from a contact in the address book but I'm not able to do it
I'm using this code that I found "googling":
- (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;
}
I've put the if to validate the "socials" array is nil because I was getting exception when trying to get "socials" array count.
I've tried this code in the simulator and in a real device with contacts which twitter info is filled but the "socials" array I get is always nil. I'm getting the wrong property from the record? Any help?
Thank you in advance