0

I am trying to create a contact group in native by using following code, The Scenario i am trying is : Add any outlook account in native mail then enable contact sync, this will create a contact group. After this if i am trying to create a group from my App then its failing ..

ABAddressBookRef addressBook = ABAddressBookCreate();
    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (granted) {
                CFErrorRef error = NULL;
                ABRecordRef worxMailGroup = ABGroupCreate();
                BOOL success = ABRecordSetValue(worxMailGroup,kABGroupNameProperty,(__bridge CFTypeRef) @"TestGroup2",&error);
                if (success) {
                    bool bStatus = ABAddressBookAddRecord(addressBook, worxMailGroup, &error);
                    if (bStatus) {
                        bStatus = ABAddressBookSave(addressBook, &error);
                        // bStatus is false and error also nil ..
                    }
                }
            }
        });
    });

Thanks

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
  • You might want to cut the Gordian knot and just use Contacts framework rather than the deprecated AddressBook framework... – Rob Apr 15 '18 at 06:07
  • @Rob I tried with Contacts framework as well .. But still contact group creation failing .. – Shaik Riyaz Apr 15 '18 at 06:26
  • 1
    Use the contacts framework and show your code for that. – Paulw11 Apr 15 '18 at 06:31
  • FWIW, I tried this code in a new project and it worked (it leaks, but that's a separate question). So when you post your contacts rendition, try it in a blank project and see if it works or not. We need [reproducible example](http://stackoverflow.com/help/mcve). – Rob Apr 15 '18 at 06:40
  • @Rob It worked for you because you didn't have any existing group in your Native contact app. But if you configure some exchange account or hotmail account in native Mail and enable contact sync then it creates a group .. after that our code will fail .. – Shaik Riyaz Apr 15 '18 at 06:46

0 Answers0