Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-18-2009, 03:50 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 2
Default Add member to an existent address group

Hi to all.
My ask is, is possible adding a new contact to an existent address group?
I have seen that in the "ABContact" application is possible. In that application is possible adding/renaming/deleting groups and adding a member in an existent group. I've tried to do this with this code, but nothing!!

Code:
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person
{

	//if the contact has saved, assign the contact to the group
	if (person != NULL)
	{
		ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
		ABRecordID groupID;
		if (![self groupIsPresent:NSLocalizedString(@"ContactGroup", @"") GroupID:&groupID])
		{
			ABRecordRef group = ABGroupCreate();
			ABRecordSetValue(group, kABGroupNameProperty, NSLocalizedString(@"ContactGroup", @""), nil);
			ABAddressBookAddRecord(iPhoneAddressBook, group, nil);
			ABGroupAddMember(group, person, nil);
			ABAddressBookSave(iPhoneAddressBook, nil);
		}
		else
		{
			CFErrorRef err;
			ABRecordRef group = ABAddressBookGetGroupWithRecordID(iPhoneAddressBook, groupID);
			if (ABGroupAddMember (group, person, &err) == NO)
				NSLog(@"(%@) - %@", (NSError *)err, [(NSError *)err userInfo]);
		}
	}
}
where the "groupIsPresent" is that function:

Code:
- (BOOL) groupIsPresent:(NSString *)groupToCheck GroupID:(ABRecordID *)groupID
{	
	ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
	CFArrayRef groupVal = ABAddressBookCopyArrayOfAllGroups(iPhoneAddressBook);
	for (int i = 0; i < ((int)ABAddressBookGetGroupCount(iPhoneAddressBook)); i ++)
	{
		ABRecordRef group = CFArrayGetValueAtIndex(groupVal, i);
		NSString *groupName = (NSString *)ABRecordCopyCompositeName(group);
		if ([groupName isEqualToString:groupToCheck])
		{
			*groupID = ABRecordGetRecordID(group);
			return YES;
		}
	}
	return NO;
}
The ID passed from the ABAddressBookGetGroupWithRecordID is ok (the group passed exist!) and the ABGroupAddMember function don't report error!! Why?! Instead, if I try to reuse the ABGroupCreate when the group is present, my code recreate a new group with the same name! It duplicates the group and ionsert the contact into the new group! The function ABGroupCreate don't check if the group with that name is present or not before creating....!!
What's the function to call for managing groups, for adding/deleting/updating the name or property of an existent group? I've finded nothing into the Apple developer SDK....(here)

Thanks in advance.
dpicinot is offline   Reply With Quote
Reply

Bookmarks

Tags
address, book, contacts, groups

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 252
24 members and 228 guests
ADY, AragornSG, bookesp, chillyh, dacapo, Dani77, Davey555, Dominus, dre, glenn_sayers, HemiMG, JasonR, karlam963, LEARN2MAKE, M.A.S., marshusensei, mer10, nobre84, Oral B, prchn4christ, Raggou, Rudy, spiderguy84, themathminister
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:28 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0