1

Greetings,

I am making an address book application so that contacts can be created under groups. I have been able to create the groups . but everytime i start the application the group is repeated .

How is that i can check if the group already exist. I had used the ABAddressBookCopyArrayOfAllGroups but havent been successful in retrievin the name of the group from that array while printting the NSLog of the array i get an

alanvabraham
  • 779
  • 2
  • 14
  • 25
  • I think group names are not unique as person name is, but you can use groupid as we use personid. – Ravin Apr 20 '11 at 12:46

1 Answers1

6
+ (BOOL)checkIfGroupExistInAddressBook:(NSString*)gName{

    BOOL gExist = NO;
    ABAddressBookRef addressBook = ABAddressBookCreate();
    NSArray *groups = (NSArray *) ABAddressBookCopyArrayOfAllGroups(addressBook);

    // Check group in existing Address book groups
    for (id _group in groups)
    {
        //NSString *currentGroupName = [[[NSString alloc] init] autorelease];
        NSString *currentGroupName = (NSString*) ABRecordCopyValue(_group, kABGroupNameProperty);
        //(ABRecordRef)group]
        // If group exist return YES
        if ([currentGroupName isEqualToString:gName]){
            gExist = YES;
            CFRelease(currentGroupName);
            break;
        }

        CFRelease(currentGroupName);
    }

    CFRelease(addressBook);
    if (groups) {[groups release];groups = nil;}

    // If group Dose not exist return NO;
    return gExist;

}
beryllium
  • 29,669
  • 15
  • 106
  • 125
Ashish Chauhan
  • 1,316
  • 15
  • 22