我正在使用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);