【问题标题】:How to add the email address to the iPhone Contacts?如何将电子邮件地址添加到 iPhone 通讯录?
【发布时间】:2010-08-30 02:03:43
【问题描述】:

我想问一个关于 iPhone Contacts 和 Objective-C 的问题。我想在我的程序中创建一个联系人并添加到 iPhone。我写了下面的代码,名字,姓氏和电话号码是好的,但我无法将电子邮件添加到联系人中。谁能帮帮我?

记录 = ABPersonCreate(); ABAddressBookRef addressBook = ABAddressBookCreate();

// add the content number
ABMutableMultiValueRef phoneNumber = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(phoneNumber, addPhoneNumber, kABPersonPhoneMobileLabel, NULL);

// The type of the addXXX is NSString *
ABRecordSetValue(record, kABPersonFirstNameProperty, addFirstName, NULL);
ABRecordSetValue(record, kABPersonLastNameProperty, addSecondName, NULL); 
ABRecordSetValue(record, kABPersonPhoneProperty, addPhoneNumber, NULL);
ABRecordSetValue(record, kABPersonEmailProperty, addEmail, NULL);  // <-- problem in here !!

ABAddressBookAddRecord(addressBook, record, NULL);
ABAddressBookSave(addressBook, NULL);

【问题讨论】:

    标签: iphone objective-c email contacts


    【解决方案1】:

    尝试将问题行替换为:

    ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(multiEmail, addEmail, kABWorkLabel, NULL);
    ABRecordSetValue(record, kABPersonEmailProperty, multiEmail, &error);
    CFRelease(multiEmail);
    

    【讨论】:

    • @没什么特别的,谢谢你的回复。复制粘贴代码后,email 的值是 .
    • @没什么特别的,它的工作。这是另一个问题,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2014-09-13
    相关资源
    最近更新 更多