How can i add contact on existing Group in iOS sdk

371 Views Asked by At

I am working on contact app in which i want to add the contact with 3 different groups (i.e. A, B, C). And for adding (creating) new contact using native contact create.

ABRecordRef person = ABPersonCreate();
ABUnknownPersonViewController *controller = [[ABUnknownPersonViewController alloc] init];
controller.displayedPerson = person;
controller.allowsAddingToAddressBook = YES;

[self.navigationController pushViewController:controller animated:YES];

This will be add the contact on contact book. But i wish to add with Group Like A,B and C.

How can i add this contact in the group with the use of native Add Contact screen.

Please help me.

1

There are 1 best solutions below

0
On

i hope it will work ,

You can achieve that by using ABNewPersonViewController available in the Addressbook Framework:

Below iOS 9:

ABNewPersonViewController *addContactVC = [[ABNewPersonViewController alloc] init];
addContactVC.newPersonViewDelegate      = self;
UINavigationController *navController   = [[UINavigationController alloc] initWithRootViewController:addContactVC];
[self presentModalViewController:navController animated:YES];

iOS 9 or greater:

You can use CNContactViewController of ContactsUI Framework :

CNContactViewController *addContactVC = [CNContactViewController viewControllerForNewContact:contact];
addContactVC.delegate                 = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addContactVC];
[self presentViewController:navController animated:NO completion:nil];