简体   繁体   中英

how to get records of contacts from NSMutableArray in iPhone

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM