简体   繁体   English

如何从iPhone中的NSMutableArray获取联系人记录

[英]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. 我试图在ABRecordRef添加该记录,但是我不知道它是如何工作的。 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 . 我正在尝试使用ABGroupAddMember将此联系人记录添加到组中。 Now how can I get the records from NSMutableArray . 现在如何从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 您将必须创建一个空记录,然后从dict中获取所有字段,然后将这些字段添加到记录中并对其进行保护

that's annoying manual work... :D 烦人的手工工作...:D

I'd go with Erica's ABContactHelper: https://github.com/erica/ABContactHelper 我会选择Erica的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 免责声明:内联键入,但应该可以

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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