Although the Address Book Programming Guide for iOS clearly explains how the ABPeoplePickerNavigationController class allows users to browse their list of contacts and select a person. I was wondering how can a 'Group' be picked instead.
How to pick a 'Group' instead of an individual 'Person' from the ABPeoplePickerNavigationController?
Asked
Active
Viewed 165 times
1 Answers
0
I don't know if your problem is solved by now. I just run into the same problem. As far as I can see, iOS does not provide a "ready made" way to access groups in the address book like the people picker http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/UI_Controllers.html.
However, you can access all group information like in the following example code (you had to add error handling), but you had to program your user interface by yourself.
CFErrorRef error;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions (NULL, &error);
CFArrayRef groups = ABAddressBookCopyArrayOfAllGroups (addressBook);
ABRecordRef firstGroup = CFArrayGetValueAtIndex (groups,0);
CFStringRef nameOfFirstGroup = ABRecordCopyCompositeName (firstGroup);
CFRelease(nameOfFirstGroup);
CFArrayRef members = ABGroupCopyArrayOfAllMembers (firstGroup);
ABRecordRef firstMember = CFArrayGetValueAtIndex (members,0);
CFStringRef nameOfFirstMember = ABRecordCopyCompositeName (firstMember);
CFRelease(nameOfFirstMember);
CFRelease(members);
CFRelease(groups);
CFRelease(addressBook);
EDIT:
Sorry, the code above releases the different objects too early. Please put the CFRelease
statements at the end of the code.

Reinhard Männer
- 14,022
- 5
- 54
- 116