views:

42

answers:

1

Hi, everyone,

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 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);
+2  A: 

Try replacing the problem line with:

ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiEmail, addEmail, kABWorkLabel, NULL);
ABRecordSetValue(record, kABPersonEmailProperty, multiEmail, &error);
CFRelease(multiEmail);
No one in particular
@No one in particular, thank you for your reply. After the copy and paste the code, the value of the email is sth like <NS...>.
Questions
@No one in particular, it's work. It is another problems, thank you.
Questions