Getting group for particular contact from AddressBook iPhone

六眼飞鱼酱① 提交于 2020-01-14 02:51:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!