本文介绍了如何将联系人信息从vCard保存到iPhone的联系人应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的iPhone应用程序中,当我点击vCard时,我想将vCard保存到我的iPhone的联系人中。
我如何做? / p>
我在应用商店中看到了一个应用,它执行此操作:
p>
感谢
解决方案
c $ c> iPhone的联系人。
正如我告诉你,我不知道任何关于 vCard
,但这个代码可能是有用的:
ABAddressBookRef addressBook = ABAddressBookCreate(); //创建地址簿记录
ABRecordRef person = ABPersonCreate(); // create a person
NSString * phone = @0123456789; //要添加的电话号码
//电话号码是电话号码的列表,因此创建多值
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABPersonPhoneProperty);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue,phone,kABPersonPhoneMobileLabel,NULL);
ABRecordSetValue(person,kABPersonFirstNameProperty,@FirstName,nil); //新人的名字
ABRecordSetValue(person,kABPersonLastNameProperty,@LastName,nil); // his last name
ABRecordSetValue(person,kABPersonPhoneProperty,phoneNumberMultiValue,& anError); //设置电话号码属性
ABAddressBookAddRecord(addressBook,person,nil); //将新的人添加到记录
ABRecordRef group = ABGroupCreate(); // create a group
ABRecordSetValue(group,kABGroupNameProperty,@My Group,& error); // set group's name
ABGroupAddMember(group,person,& error); //将人添加到组
ABAddressBookAddRecord(addressBook,group,& error); // add the group
ABAddressBookSave(addressBook,nil); //保存记录
CFRelease(person); // relase the ABRecordRef variable
In my iPhone app, I want to save the vCards into my iPhone's Contacts when I click onto the vCard which I have.
How can I do that?
I have seen an app on app store which does this:
http://itunes.apple.com/us/app/read-vcard/id402216831?mt=8
Thanks
解决方案
Following is the code for adding user information in iPhone's Contact
.
As I told you that i dont know anything about the vCard
, but this code posted by malinois in their answer here might be of use:
ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book record
ABRecordRef person = ABPersonCreate(); // create a person
NSString *phone = @"0123456789"; // the phone number to add
//Phone number is a list of phone number, so create a multivalue
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABPersonPhoneProperty);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,phone,kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(person, kABPersonFirstNameProperty, @"FirstName" , nil); // first name of the new person
ABRecordSetValue(person, kABPersonLastNameProperty, @"LastName", nil); // his last name
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, &anError); // set the phone number property
ABAddressBookAddRecord(addressBook, person, nil); //add the new person to the record
ABRecordRef group = ABGroupCreate(); //create a group
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", &error); // set group's name
ABGroupAddMember(group, person, &error); // add the person to the group
ABAddressBookAddRecord(addressBook, group, &error); // add the group
ABAddressBookSave(addressBook, nil); //save the record
CFRelease(person); // relase the ABRecordRef variable
这篇关于如何将联系人信息从vCard保存到iPhone的联系人应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!