我有一个应用程序,它使用以下方式在联系人中添加名字和姓氏作为新联系人

  #import <AddressBook/AddressBook.h>

这就是我添加名字和姓氏的方式:
 [self addAccountWithFirstName:self.firstNameField.text lastName:self.lastNameField.text  inAddressBook:addressBook];

我要添加电话号码和电子邮件。怎么做 ?

最佳答案

    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);
}

10-08 14:26