1

I have an application which adds the first and last name as new contact in the contacts using

  #import <AddressBook/AddressBook.h>

and this is how I added the first and last name:

 [self addAccountWithFirstName:self.firstNameField.text lastName:self.lastNameField.text  inAddressBook:addressBook];

I want to add the phone number and the email. How to do it ?

1 Answer 1

1
    CFErrorRef error = NULL; 
NSLog(@"%@", [self description]);
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();

ABRecordRef newPerson = ABPersonCreate();

ABRecordSetValue(newPerson, kABPersonFirstNameProperty, people.firstname, &error); ABRecordSetValue(newPerson, kABPersonLastNameProperty, people.lastname, &error);

ABMutableMultiValueRef multiPhone =         ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, people.phone, kABPersonPhoneMainLabel, NULL);
ABMultiValueAddValueAndLabel(multiPhone, people.other, kABOtherLabel, NULL);            
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);
    // ... 
    // Set other properties
    // ...
    ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);

ABAddressBookSave(iPhoneAddressBook, &error);
    CFRelease(newPerson);
    CFRelease(iPhoneAddressBook);
if (error != NULL) 
{
       CFStringRef errorDesc = CFErrorCopyDescription(error);
   NSLog(@"Contact not saved: %@", errorDesc);
       CFRelease(errorDesc);        
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.