iPhone将联系人添加到通讯录中的现有群组 [英] Iphone Add contact to existing group in address book
本文介绍了iPhone将联系人添加到通讯录中的现有群组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用一个与通讯录联系人一起使用的iPhone应用程序.我试图在联系人中创建组,但是问题是当我再次运行该应用程序时,再次创建了该组,并且新的联系人被保存到了新创建的组中.
I am working on an iPhone application which works with the address book contacts. I am trying to get make groups in the contacts but the problem is when I run the application again the group is created again and the new contact is saved to that new created group.
// create address book record
ABAddressBookRef addressBook = ABAddressBookCreate();
// create a person
ABRecordRef person = ABPersonCreate();
// name of the new person
ABRecordSetValue(person, kABPersonFirstNameProperty, [index objectAtIndex:3], nil);
ABRecordSetValue(person, kABPersonLastNameProperty, [index objectAtIndex:0], nil);
//add the new person to the record
ABAddressBookAddRecord(addressBook, person, nil);
ABAddressBookSave(addressBook, &error);
ABAddressBookAddRecord(addressBook, group, &error); // add the group
ABAddressBookSave(addressBook, &error);
ABRecordRef group = ABGroupCreate(); //create a group
ABGroupAddMember(group, person, &error); // add the person to the group
ABAddressBookSave(addressBook, &error);
//save the record
ABAddressBookSave(addressBook, nil);
// relase the ABRecordRef variable
CFRelease(person);
那是我一直在努力的代码.
That's the code I have been working on.
推荐答案
ABRecordRef group = ABGroupCreate();
,
它将创建一个新的组...如果要在现有组中添加成员,则应按其ID获得组.更新代码
It will create a new group... If you wan to add member in existing group then you should get group by its id. Updated Code
ABRecordRef group = ABAddressBookGetGroupWithRecordID(addressBookInstance,putYourGroupIdHere);
谢谢
这篇关于iPhone将联系人添加到通讯录中的现有群组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文