开发者

How to add the email address to the iPhone Contacts?

开发者 https://www.devze.com 2023-01-13 20:47 出处:网络
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 num

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

精彩评论

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