iphone - How to modify existing ios ABRecord address -


i trying edit existing ios contact. contacts can have number of addresses , want edit 1 of those. able add new address contact can not edit it. have tried abmultivaluereplacevalueatindex not helping. here code snippet

cferrorref error = null; abaddressbookref addrbook = abaddressbookcreate(); abrecordref existingcontact = abaddressbookgetpersonwithrecordid(addrbook, contact.devicerecordid);  abrecordsetvalue(existingcontact, kabpersonfirstnameproperty,(__bridge cftyperef)(contact.firstname) , &error); abrecordsetvalue(existingcontact, kabpersonlastnameproperty, (__bridge cftyperef)(contact.lastname) , &error);  // current addresses abmultivalueref addresses = abrecordcopyvalue(existingcontact, kabpersonaddressproperty); abmutablemultivalueref multiaddress = abmultivaluecreatemutablecopy(addresses);  // append street line 1 \n delimited string. nsmutablestring *streets = [[nsmutablestring alloc] init]; if (contact.address.street1 != nil) {     [streets appendstring:contact.address.street1]; } if (contact.address.street2 != nil) {     [streets appendformat:@"\n%@",contact.address.street2]; } if (contact.address.street3 != nil) {     [streets appendformat:@"\n%@",[contact.address.street3 stringbyreplacingoccurrencesofstring:spaadditionalstreetseparator withstring:@"\n"]]; }  // single address nsmutabledictionary *addr = [[nsmutabledictionary alloc] init];   // insert single address multi address specified label cftyperef ctr = cfbridgingretain(addr); abmultivalueaddvalueandlabel(multiaddress, ctr, (cfstringref)@"work", null); //abmultivaluereplacevalueatindex(multiaddress, ctr, index);  // add multiaddress value person object abrecordsetvalue(existingcontact, kabpersonaddressproperty, multiaddress, &error);  abaddressbooksave(addrbook, &error); 

just realized abmultivaluereplacevalueatindex want. there bug in code earlier.


Comments