如何添加“自定义标签"以编程方式到 iOS 地址簿? [英] How to add a "Custom Label" to iOS AddressBook programmatically?

查看:145
本文介绍了如何添加“自定义标签"以编程方式到 iOS 地址簿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iOS 通讯录中手动添加联系人的电话/IMS 时,您可以添加自定义标签而不是家庭"、工作"、其他"*(在 IMS 中).

When manually adding a contact's phone / IMS in the iOS AddressBook, you can add a Custom Label instead of "Home", "Work", "Other" * (in IMS).

如何以编程方式在地址簿中创建自定义标签"?

How to create "Custom Label" in AddressBook programmatically?

推荐答案

我也有同样的问题.我找不到答案,所以我只是尝试了猜测和检查方法.以下代码似乎有效:

I had this exact same question. I couldn't find an answer so I just tried the guess and check method. The following code seems to work:

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

If you check the address book, you will see a phone number with a custom label: mylabel

感谢:这篇文章

到:这个博客

这篇关于如何添加“自定义标签"以编程方式到 iOS 地址簿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆