October 2013
Intermediate to advanced
1053 pages
28h 7m
English
You want to assign a person entry in the address book to a group.
Use the ABGroupAddMember
function.
We learned to insert both person entries (in Recipe 13.5) and group
entries (in Recipe 13.6) into the
address book database. In those recipes we implemented two custom
methods named newPersonWithFirstName:lastName:inAddressBook:
and newGroupWithName:inAddressBook:.
Now we want to add the person entry to the group we created and save the
information to the address book database. Combining these three recipes,
we can use the following code to achieve our
goal:
-(BOOL)addPerson:(ABRecordRef)paramPersontoGroup:(ABRecordRef)paramGroupsaveToAddressBook:(ABAddressBookRef)paramAddressBook{BOOLresult=NO;if(paramPerson==NULL||paramGroup==NULL||paramAddressBook==NULL){NSLog(@"Invalid parameters are given.");returnNO;}CFErrorReferror=NULL;/* Now attempt to add the person entry to the group */result=ABGroupAddMember(paramGroup,paramPerson,&error);if(result==NO){NSLog(@"Could not add the person to the group.");returnresult;}/* Make sure we save any unsaved changes */if(ABAddressBookHasUnsavedChanges(paramAddressBook)){BOOLcouldSaveAddressBook=NO;CFErrorRefcouldSaveAddressBookError=NULL;couldSaveAddressBook=ABAddressBookSave(paramAddressBook,&couldSaveAddressBookError);if(couldSaveAddressBook){NSLog(@"Successfully added the person to the group.");result=YES;}else{NSLog(@"Failed ...
Read now
Unlock full access