Reputation: 11338
I'm adding contacts in group of iphone by my application. Is there any other logic ??
Can anybody tell me how can i check the groups existence ???
I am using follwing code to check the group's existence but may be b'coz of loops my app s crash in iphone.
//ab=AddressBook object
CFArrayRef a = ABAddressBookCopyArrayOfAllGroups(ab);
for (CFIndex i = CFArrayGetCount(a)-1; i >= 0; i--)
{
ABRecordRef g = (ABRecordRef) CFArrayGetValueAtIndex(a, i);
CFStringRef s = (CFStringRef) ABRecordCopyValue(g, kABGroupNameProperty);
CFComparisonResult r = CFStringCompare((CFStringRef)name, s, 0);
CFRelease(s);
if (r == kCFCompareEqualTo)
{
group = CFRetain(g);
break;
}
}
CFRelease(a);
CFErrorRef err = nil;
if (!group)
{
group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty, name, &err);
if (!err)
{
ABAddressBookAddRecord(ab, group, &err);
}
if (!err)
{
ABAddressBookSave(ab, &err);
}
}
if (err)
{
CFRelease(err);
}
Upvotes: 0
Views: 1023
Reputation: 31720
From Apple Documentation:
You can find a specific group by record identifier using the function ABAddressBookGetGroupWithRecordID
. You can also retrieve an array of all the groups in an address book using ABAddressBookCopyArrayOfAllGroups
, and get a count of how many groups there are in an address book using the function ABAddressBookGetGroupCount
.
You can modify the members of a group programatically. To add a person to a group, use the function ABGroupAddMember
; to remove a person from a group, use the function ABGroupRemoveMember
. Before a person record can be added to a group, it must already be in the Address Book database. If you need to add a new person record to a group and to the database at the same time, you must first add it to the address book database, save the database, and then add the person record to the group.**
For more plz read apple documentation.
Upvotes: 1