0

I have an array of dictionary for contact details. I am trying to add that record in ABRecordRef, but I don't understand how it works. Here is my code:

for (int i = 0; i <= [contactArray count]; i++)
{
    ABRecordRef person = (ABRecordRef)[contactArray objectAtIndex:i];
    ABAddressBookAddRecord(addressBook, group, &error);
    ABAddressBookSave(addressBook, &error);
}

I am trying to add this contact records into group using ABGroupAddMember. Now how can I get the records from NSMutableArray. Any help will be greatly appreciated. Thank you.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • you want to convert dictionaries to ABRecordRefs? (that's what I get here :D) – Daij-Djan May 02 '13 at 06:34
  • @Daij-Djan Yes, in dictionary I have the firstName,lastName,emailId, phone number of one person I want to add all the values from dictionary for adding that contact into group. – user2336918 May 02 '13 at 06:41
  • Maybe this solved question helps - [Copying NSDictionary to NSArray](http://stackoverflow.com/questions/5788694/copying-nsdictionary-to-nsarray) – Vikr May 02 '13 at 06:46
  • please edit the question title to reflect what you really want – Daij-Djan May 02 '13 at 08:23

1 Answers1

0

there is no built-in functionality for that. you will have to create an empty record, THEN get all the fields from the dict and THEN add those to the record and safe it

that's annoying manual work... :D

I'd go with Erica's ABContactHelper: https://github.com/erica/ABContactHelper

then it is only

for(NSDictionary *d in recordArray) {
    ABContact *contact = [ABContact contactWithDictionary:d];
    ABGroupAddMember(theGroup, contact.record);
}

if you like manual:

for(NSDictionary *d in recordArray) {
    ABRecordRef person = ABPersonCreate();

    for(NSString *k in d.allKeys) {
        id v = d[k];
        //HERE call ABRecordSetValue with the right params depending on if the value is a NSString or NSArray or an image
    }

    ABGroupAddMember(theGroup, contact.record);
    CFRelease(person);
}

disclaimer: typed inline but should be ok

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135