2010-08-30 144 views
1

我想問一個關於iPhone聯繫人和Objective-C的問題。我想在我的程序中創建一個聯繫人並添加到iPhone。我寫下面的代碼,名字,姓氏和電話號碼是好的,但我不能將電子郵件添加到聯繫人。誰能幫我?如何將電子郵件地址添加到iPhone聯繫人?

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); 

回答

5

嘗試與更換問題行:特別

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

@No一個,謝謝您的回覆。複製並粘貼代碼後,電子郵件的價值就像。 – Questions 2010-09-01 01:28:15

+0

@特別沒有,這是工作。這是另一個問題,謝謝。 – Questions 2010-09-01 02:27:04

相關問題