I am wondering if there is a way to get the group (s) to which a particular contact belongs?
Let's say I got an array of all the contacts:
NSMutableArray *people = [[[(NSArray*) ABAddressBookCopyArrayOfAllPeople(addressBook) autorelease] mutableCopy] autorelease];
and then repeat them:
for (int personN = 0; personN < [people count]; personN++) { ABRecordRef person = [people objectAtIndex:personN]; NSString* firstName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
How can I get the name (s) of a group for a person? MacOS has an ABPerson class that has a parentGroups method that does what I need, but I don't see anything like it on iOS.
I believe that instead you can get an array of all groups, then repeat this array of groups and get contact entries for each group, but I was hoping there was a more direct way for this?
PS There seems to be no way to do this, but iterate over groups. One caveat for those who find this question later: to get all the contacts, you need to iterate over the groups and get the members of each group (ABGroupCopyArrayOfAllMembers), and then iterate over all the contacts (ABAddressBookCopyArrayOfAllPeople), because there is no "zero" group. Also note that ABAddressBookCopyArrayOfAllPeople will also provide you with the contacts you already received with calls to ABGroupCopyArrayOfAllMembers, so be sure to check for duplicates.
ios iphone cocoa-touch
SVD
source share