-1

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? :)

hinderberg
  • 414
  • 1
  • 3
  • 11

1 Answers1

1

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

shannoga
  • 19,649
  • 20
  • 104
  • 169
  • This is the same way I do it, and some how this doesn't work when i'm on the iPhone (iOS 4.2.1). It may have something to do with the address book setup I use on my iPhone and that it will try to add a group to one of my exchange accounts. So how do you specify that a group should be saved locally or something? :) – hinderberg Feb 05 '11 at 18:37