开发者

How to add the email address to the iPhone Contacts?

I want to ask a question about the iPhone Contacts and objective-C. I want to create a contacts in my program and add to the iPhone. I write the following code, the first name, last name and phone number is good, but I cannot add the email to the contacts. Can anyone help me?

record = ABPersonCreate(); ABAddressBookRef addre开发者_高级运维ssBook = 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);


Try replacing the problem line with:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜