Question

Hey I'm trying to add an ABPerson to an ABGroup. I get no errors or anything. My output tells me the person has been added successfully.

if(ABGroupAddMember(self.group, [allContacts objectAtIndex:indexPath.row], &error))
            NSLog(@"Added person: %@ to group: %@", ABRecordCopyCompositeName([allContacts objectAtIndex:indexPath.row]), ABRecordCopyCompositeName(self.group));

if(ABAddressBookSave(self.addressBook, &error))
        NSLog(@"Commited changes.");

These two statements return the correct output.

But upon querying the group members, I get an empty array.

NSLog(@"%@", ABGroupCopyArrayOfAllMembers(self.group)); //returns null

If anybody has any ideas, I'd really appreciate it.

Was it helpful?

Solution

Wow not 5 minutes after posting, I've found the problem. After editing the group, I have to add it back to the address book like so:

ABAddressBookAddRecord(addressBook, group, &error);

if(ABAddressBookSave(addressBook, &error))
    NSLog(@"Commited changes.");

OTHER TIPS

Just as an FYI, some sources (ABSource, e.g. MSExchange) do not support group creation.

There are some details and code examples on specifying sources (iOS 4+ only) here: Obtaining Specific ABSource from ABAddressBook in iOS 4+

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top