在iphone的地址簿中创建一个组 [英] create a group in address book for iphone

查看:77
本文介绍了在iphone的地址簿中创建一个组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

我在iphone应用程序中工作,该应用程序使用添加联系人到地址簿。我已经能够将联系人添加到地址簿中,但我面临的问题是在我创建的组中添加联系人记录。联系是在不在组中已创建的所有联系人下创建的。
下面是我使用的代码

I am working in an iphone application which uses adding contact to the address book. I have been able to add contacts to the address book but the problem i am facing is while adding a contact record to a group that i have created. The contact is created under all contacts not within the group which have been created. Below is the code i have used

// create address book record
ABAddressBookRef addressBook = ABAddressBookCreate(); 
// create a person  
ABRecordRef person = ABPersonCreate();  
// first name of the new person
ABRecordSetValue(person, kABPersonFirstNameProperty, @"FirstName" , nil);
// his last name 
ABRecordSetValue(person, kABPersonLastNameProperty, @"LastName", nil);  
//add the new person to the record
ABAddressBookAddRecord(addressBook, person, nil); 

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   

//save the record
ABAddressBookSave(addressBook, nil);  

// relase the ABRecordRef  variable
CFRelease(person);  

非常感谢有关这方面的任何帮助

I would appreciate any help available on this regard

谢谢!

推荐答案

首先需要将人员保存到地址簿,然后再将其添加到群组中,意味着你必须添加一个

You first need to save the Person to the address book before adding it to the group, this means you have to add an

ABAddressBookSave(addressBook, nil);

在将此人添加到组之前,在您的情况下,它将在创建组之前。

Before adding the person to the group, in your case it will be just before creating the group.

这篇关于在iphone的地址簿中创建一个组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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