开发者

Iphone - Check if a group name already exist in addressbook

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 a开发者_JS百科rray while printting the NSLog of the array i get an


+ (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;

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜