Search code examples
objective-ccocoa-touchabaddressbook

Cocoa-Touch – Opposite of ABGroupCreate (delete group)


Is there any way that you can delete groups programatically? You can create them with ABGroupCreate() so logically there should be a delete function also? Or is that considered too hazardous (in a way that evil programmers can delete the user's groups?)


Solution

  • Remove group members with ABGroupRemoveMember.

    EDIT: Another idea: an ABGroup is an ABRecord, and you can remove an ABRecord with ABAddressBookRemoveRecord.

    ANOTHER EDIT: And in fact see Apple's ABUIGroups example, which contains this code:

    - (void)deleteGroup:(ABRecordRef)group fromAddressBook:(ABAddressBookRef)myAddressBook
    {
        CFErrorRef error = NULL;
        ABAddressBookRemoveRecord(myAddressBook, group, &error);
        ABAddressBookSave(myAddressBook,&error);
    }
    

    So there you go.