如何将电话号码和电子邮件添加到地址簿

时间:2014-07-03 11:56:44

标签: ios objective-c

我有一个应用程序,使用

将姓氏和姓氏添加为联系人中的新联系人
  #import <AddressBook/AddressBook.h>

这就是我添加名字和姓氏的方式:

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

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

1 个答案:

答案 0 :(得分:1)

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

ABRecordRef newPerson = ABPersonCreate();

ABRecordSetValue(newPerson,kABPersonFirstNameProperty,people.firstname,&amp; error);     ABRecordSetValue(newPerson,kABPersonLastNameProperty,people.lastname,&amp; 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);        
}
相关问题