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

标签 ios objective-c

我有一个应用程序,它使用

在联系人中添加名字和姓氏作为新联系人
  #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);        
}

关于ios - 如何将电话号码和电子邮件添加到地址簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24553078/

相关文章:

ios - 如何使用 Parse 保存 UITextField?

ios - Xcode 更改存储库

ios - 架构 armv7 的 undefined symbol : "_objc_readClassPair", 引用自 : __ARCLite__load() in libarclite_iphoneos. a(arclite.o)

ios - 如何将数组元素分配给属性?

iphone - iOS 应用元数据被拒绝 : MFi Certification PPID #

objective-c - CocoaPods/Podspec 和 *.framework

ios - UISwitch 需要 OFF 然后 ON 单击(反之亦然)才能将其设置为 "save"值并正常工作

ios - cordova ios 中的基本身份验证失败

ios - 如何使用底层 WKWebKit 自动调整 UITableViewCell 的大小,使其尊重 Web View 的内容?

iphone - 如何手动删除 UITableView 中的一行?