问题
I am getting group name for particular contact in my addressbook, but below code returns me wrong group name for example if contact C1 is from group G1 then code gives me group G2.
Can anyone tell me what am I doing wrong here?
*Code
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSInteger recordId;
ABRecordRef recordGroupID;
for( int i=0;i< nPeople;i++)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
@try {
NSAutoreleasePool *Pool = [[NSAutoreleasePool alloc] init];
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
recordId = ABRecordGetRecordID(ref);
recordGroupID = ABAddressBookGetGroupWithRecordID(addressBook, recordId);
NSString *grpName;
if(recordGroupID)
grpName = (NSString *)ABRecordCopyCompositeName(recordGroupID);
else
grpName = @"";
[dict setObject:grpName forKey:@"GroupName"];
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
.....
and so on
}
来源:https://stackoverflow.com/questions/8252366/getting-group-for-particular-contact-from-addressbook-iphone