Question

In my app I export some data to the address book in order to create some new contact entries. I can export everything I want to without problem, except Facebook and Twitter addresses. I'm completely lost on these two.

Here's some code I'm using to export non-Facebook/Twitter data that DOES work:

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(thePhoneMobile), kABPersonPhoneMobileLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)(thePhoneHome), kABHomeLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone, NULL);
CFRelease(multiPhone);

Here's how I'm trying to export Facbeook which does NOT work:

ABMutableMultiValueRef multiSocial = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiSocial, (__bridge CFTypeRef)(theFacebook), kABPersonSocialProfileServiceFacebook, NULL);
ABRecordSetValue(newPerson, kABPersonSocialProfileProperty, multiSocial, NULL);
CFRelease(multiSocial);

Where am I going wrong?

Was it helpful?

Solution

Setting social profiles is very tricky for some reason, but here is the code necessary to doing so:

ABMultiValueRef multiSocial = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);

ABMultiValueAddValueAndLabel(multiSocial, (__bridge CFTypeRef)([NSDictionary dictionaryWithObjectsAndKeys:(NSString *)kABPersonSocialProfileServiceFacebook, kABPersonSocialProfileServiceKey, theFacebook, kABPersonSocialProfileUsernameKey,nil]), kABPersonSocialProfileServiceFacebook, NULL);

ABRecordSetValue(newPerson, kABPersonSocialProfileProperty, multiSocial, NULL);

According to the documentation, the social profiles is a kABMultiDictionaryPropertyType, not kABMultiStringType.

That also means that you need to add dictionaries to multiSocial, not strings. The format does not make sense to me for the dictionary, so just copy and paste whenever you need to use it.

Then, you set it how you did before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top