Reputation: 69
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 ?
Upvotes: 1
Views: 93
Reputation: 162
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);
}
Upvotes: 1