开发者

Get Address Book contact's group?

I'm wondering if there's a way to get the group(s) a particular contact belongs to?

Let's say I got the array of all contacts:

NSMutableArray *people = [[[(NSArray*) 
      ABAddressBookCopyArrayOfAllPeople(addressBook) autorelease] 
      mutableCopy] autorelease];

and then iterate through them:

for (int personN = 0; personN < [people count]; personN++) {
ABRecordRef person = [people objectAtIndex:personN];
NSString* firstName = (NSString*)ABRecordCopyValue(person, 
            开发者_JAVA百科          kABPersonFirstNameProperty);
//and so on...
} 

How can I get the group name(s) for the person? On MacOS there's ABPerson class that has parentGroups method that does what I need, but I don't see anything like that on iOS.

I suppose it is possible to instead get the array of all groups, then iterate though that groups array and retrieve the contact records for each group, but I was hoping there was a more direct way for that?

P.S. Looks like there is no way to do that but to iterate through groups. One caveat for those who'd find this question later: to get all contacts, you have to iterate through groups and get members of each group (ABGroupCopyArrayOfAllMembers), then iterate through all contacts (ABAddressBookCopyArrayOfAllPeople) because there's no "null" group. Also note that ABAddressBookCopyArrayOfAllPeople will also give you the contacts you already fetched with ABGroupCopyArrayOfAllMembers calls, so be sure to check for duplicates.


check out http://ericasadun.com for ABRecordHelper

there is a method to return the group name from a recordID. very helpful wrapper.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜