加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在iPhone的地址簿中创建一个组

发布时间:2020-12-14 17:36:37 所属栏目:百科 来源:网络整理
导读:我正在使用iPhone应用程序,该应用程序使用地址簿添加联系人.我已经能够将联系人添加到地址簿中,但我遇到的问题是在我创建的组中添加联系人记录时. 联系是在不在组中已创建的所有联系人下创建的.以下是我使用过的代码 // create address book recordABAddress
我正在使用iPhone应用程序,该应用程序使用地址簿添加联系人.我已经能够将联系人添加到地址簿中,但我遇到的问题是在我创建的组中添加联系人记录时.

联系是在不在组中已创建的所有联系人下创建的.以下是我使用过的代码

// 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,&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);

解决方法

首先需要将Person保存到地址簿,然后再将其添加到组中,这意味着您必须添加一个

ABAddressBookSave(addressBook,nil);

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读