我正在尝试将选定的联系人添加到特定组中,但联系人无法添加到组中。我想创建新组并将联系人添加到该组中。但是在该组中创建组后无法添加联系人。这是我创建新组并将联系人添加到组中的代码:
addressBook = ABAddressBookCreateWithOptions(nil, &err);
group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty, txtGroupNameText.text, &err);
ABAddressBookAddRecord(addressBook, group, &err);
ABAddressBookSave(addressBook, &err);
groupId = ABRecordGetRecordID(group);
并添加联系人:
ABRecordRef person = [contactArray objectAtIndex:i];
ABRecordRef HiByeGroup = ABAddressBookGetGroupWithRecordID(addressBook, self.groupId);
BOOL didAdd = ABGroupAddMember(HiByeGroup,person,&err);
if (didAdd) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error while adding person to HiBye group");
}
BOOL didSave = ABAddressBookSave(addressBook, &err);
if (didSave) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error while saving address book");
}
联系人保存但未添加。请帮助我,谢谢。