Hi to all.
My ask is, is possible adding a new contact to an existent address group?
I have seen that in the "ABContact" application is possible. In that application is possible adding/renaming/deleting groups and adding a member in an existent group. I've tried to do this with this code, but nothing!!
Code:
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person
{
//if the contact has saved, assign the contact to the group
if (person != NULL)
{
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
ABRecordID groupID;
if (![self groupIsPresent:NSLocalizedString(@"ContactGroup", @"") GroupID:&groupID])
{
ABRecordRef group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty, NSLocalizedString(@"ContactGroup", @""), nil);
ABAddressBookAddRecord(iPhoneAddressBook, group, nil);
ABGroupAddMember(group, person, nil);
ABAddressBookSave(iPhoneAddressBook, nil);
}
else
{
CFErrorRef err;
ABRecordRef group = ABAddressBookGetGroupWithRecordID(iPhoneAddressBook, groupID);
if (ABGroupAddMember (group, person, &err) == NO)
NSLog(@"(%@) - %@", (NSError *)err, [(NSError *)err userInfo]);
}
}
}
where the "groupIsPresent" is that function:
Code:
- (BOOL) groupIsPresent:(NSString *)groupToCheck GroupID:(ABRecordID *)groupID
{
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
CFArrayRef groupVal = ABAddressBookCopyArrayOfAllGroups(iPhoneAddressBook);
for (int i = 0; i < ((int)ABAddressBookGetGroupCount(iPhoneAddressBook)); i ++)
{
ABRecordRef group = CFArrayGetValueAtIndex(groupVal, i);
NSString *groupName = (NSString *)ABRecordCopyCompositeName(group);
if ([groupName isEqualToString:groupToCheck])
{
*groupID = ABRecordGetRecordID(group);
return YES;
}
}
return NO;
}
The ID passed from the ABAddressBookGetGroupWithRecordID is ok (the group passed exist!) and the ABGroupAddMember function don't report error!! Why?! Instead, if I try to reuse the ABGroupCreate when the group is present, my code recreate a new group with the same name! It duplicates the group and ionsert the contact into the new group! The function ABGroupCreate don't check if the group with that name is present or not before creating....!!

What's the function to call for managing groups, for adding/deleting/updating the name or property of an existent group? I've finded nothing into the Apple developer SDK....(
here)
Thanks in advance.