Next generation's garbage RSS 2.0
# Thursday, May 24, 2012
Ok, there are some examples out there, but they were all lacking the social part (twitter, facebook) and that part is a little different so I thought I'd document that here with a more complete example of populating an ABPersonRef person.

    CFErrorRef err = NULL;
    {
        ABRecordRef person = ABPersonCreate(); // create a person
        ABRecordSetValue(person, kABPersonFirstNameProperty, CFSTR("Hafthor"), &err);
        ABRecordSetValue(person, kABPersonLastNameProperty, CFSTR("Stefansson"), &err);
        ABRecordSetValue(person, kABPersonMiddleNameProperty, CFSTR("-"), &err);
        ABRecordSetValue(person, kABPersonPrefixProperty, CFSTR("Mr."), &err);
        ABRecordSetValue(person, kABPersonNicknameProperty, CFSTR("H"), &err);
        ABRecordSetValue(person, kABPersonOrganizationProperty, CFSTR("Parsus Solutions, LLC"), &err);
        ABRecordSetValue(person, kABPersonJobTitleProperty, CFSTR("Software Architect"), &err);
        ABRecordSetValue(person, kABPersonDepartmentProperty, CFSTR("Software"), &err);
        ABRecordSetValue(person, kABPersonNoteProperty, CFSTR("Line 1\nLine 2"), &err);
        
        {
            ABMultiValueRef emails = ABMultiValueCreateMutable(kABMultiStringPropertyType);
            // string splits to foil spam harvesting
ABMultiValueAddValueAndLabel(emails, @"hafthor" "@" "parsus.com", kABWorkLabel, NULL); ABMultiValueAddValueAndLabel(emails, @"hafthor" "@" "freachable.net", kABHomeLabel, NULL); ABMultiValueAddValueAndLabel(emails, @"hafthors" "@" "gmail.com", kABOtherLabel, NULL); ABRecordSetValue(person, kABPersonEmailProperty, emails, &err); CFRelease(emails); } { ABMultiValueRef phones = ABMultiValueCreateMutable(kABMultiStringPropertyType); ABMultiValueAddValueAndLabel(phones, @"480-" "614-9000", kABWorkLabel, NULL); ABMultiValueAddValueAndLabel(phones, @"480-" "236-1210", kABHomeLabel, NULL); ABMultiValueAddValueAndLabel(phones, @"412-" "HAF-THOR", kABOtherLabel, NULL); ABRecordSetValue(person, kABPersonPhoneProperty, phones, &err); CFRelease(phones); } { ABMultiValueRef addr = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType); { CFStringRef keys[] = { kABPersonAddressStreetKey, kABPersonAddressCityKey, kABPersonAddressStateKey,
kABPersonAddressZIPKey, kABPersonAddressCountryCodeKey }, values[] = {
CFSTR("14358 N Frank Lloyd Wright Blvd.\nSuite 15"), CFSTR("Scottsdale"), CFSTR("AZ"),
CFSTR("85260"), CFSTR("us") }; ABMultiValueAddValueAndLabel(addr, CFDictionaryCreate(kCFAllocatorDefault, (void*)keys, (void*)values,
5, NULL, NULL), kABWorkLabel, NULL); } ABRecordSetValue(person, kABPersonAddressProperty, addr, &err); CFRelease(addr); } { ABMultiValueRef social = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType); { CFStringRef keys[] = { kABPersonSocialProfileServiceKey, kABPersonSocialProfileUsernameKey,
kABPersonSocialProfileURLKey }, valuestw[] = { kABPersonSocialProfileServiceTwitter,
CFSTR("hafthor"), CFSTR("http://www.twitter.com/hafthor") }, valuesfb[] = {
kABPersonSocialProfileServiceFacebook, CFSTR("hafthor"),
CFSTR("http://www.facebook.com/hafthor") }; ABMultiValueAddValueAndLabel(social, CFDictionaryCreate(kCFAllocatorDefault, (void*)keys,
(void*)valuestw, 3, NULL, NULL), NULL, NULL); ABMultiValueAddValueAndLabel(social, CFDictionaryCreate(kCFAllocatorDefault, (void*)keys,
(void*)valuesfb, 3, NULL, NULL), NULL, NULL); } ABRecordSetValue(person, kABPersonSocialProfileProperty, social, NULL); CFRelease(social); } // let's add this to the address book
ABAddressBookAddRecord(addressBook, person, &err);
CFRelease(person); }

Thursday, May 24, 2012 9:38:58 AM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
Objective C
Archive
<May 2013>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
All Content © 2013, Hafthor Stefansson - Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. - Sign In