0

I know how to get all people from the address book with ABAddressBookCopyArrayOfAllPeople() but how do I get a list of the different groups and more specifically how to I get contacts from a certain group.

I tried my luck with kABGroupNameProperty but that did not return group names - instead some often (null) and some times first names.

Thanks

Joseph
  • 9,171
  • 8
  • 41
  • 67

1 Answers1

2

I think this is what you want:

CFArrayRef groups = ABAddressBookCopyArrayOfAllGroups(addressBook);
int count = ABAddressBookGetGroupCount(addressBook);
for (int i = 0; i < count; i++) {
    ABRecordRef group = CFArrayGetValueAtIndex(groups, i);
    NSString *name = (__bridge NSString *)(ABRecordCopyValue(group, kABGroupNameProperty));
    if ([name isEqualToString:@"name of group you're looking for"]) {
        CFArrayRef people = ABGroupCopyArrayOfAllMembers(group);
        // do something with people in group
    }
}
Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92
  • Hey I have similar requirement, but the group count in my case is coming as -1. Any ideas on this? – Sagrian Mar 07 '13 at 06:14