2010-04-20 43 views

回答

11

我有这个完全相同的问题。我找不到答案,所以我只是尝试了猜测和检查方法。下面的代码似乎工作:

CFErrorRef error = NULL; 
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate(); 
ABRecordRef newPerson = ABPersonCreate(); 
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, @"Jane", &error); 
ABRecordSetValue(newPerson, kABPersonLastNameProperty, @"Smith", &error); 

const CFStringRef customLabel = CFSTR("mylabel"); 

//phone 
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
ABMultiValueAddValueAndLabel(multiPhone, @"1-444-444-444", kABPersonPhoneMainLabel, NULL); 
ABMultiValueAddValueAndLabel(multiPhone, @"1-333-333-333", kABPersonPhoneMobileLabel, NULL);    
ABMultiValueAddValueAndLabel(multiPhone, @"1-666-666-666", kABOtherLabel, NULL);   
ABMultiValueAddValueAndLabel(multiPhone, @"1-555-555-555", customLabel, NULL); 
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil); 
CFRelease(multiPhone); 

ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error); 
ABAddressBookSave(iPhoneAddressBook, &error); 

if (error != NULL) 
{ 
    NSLog(@"Error!"); 
} 

如果选中地址簿中,你会看到一个自定义标签的电话号码:mylabel

感谢:this post

而且到:this blog

+0

对我来说很好,非常感谢! – Will 2014-08-15 23:41:22

相关问题