ABGroupCreate problem

989 views Asked by At

I have problem with adding a group to the iOS address book. In the simulator everything works great, I add the group, and assign contacts to it. But when the same application runs on an iPhone or iPad the group is not created and the new contacts are therefore not assigned to that specific group.

The method ABGroupCreate does not return any error.

Solution please? :)

1

There are 1 answers

1
shannoga On

Since you didn't paste your code, i can not know the problem. anyway- this is a method i use in my apps, it creates a group and return its ID so you can store it for later use, works great for me-

-(NSInteger) createNewGroup:(NSString*)groupName {

    ABAddressBookRef addressBook = ABAddressBookCreate();
    ABRecordRef newGroup = ABGroupCreate();
    ABRecordSetValue(newGroup, kABGroupNameProperty,groupName, nil);
    ABAddressBookAddRecord(addressBook, newGroup, nil);
    ABAddressBookSave(addressBook, nil);
    NSInteger groupId = ABRecordGetRecordID(newGroup);
    CFRelease(addressBook);
    CFRelease(newGroup);
    return groupId;
}

Good luck shani