ios - how to save one name string and two different length array of email and phone no -


as guess simple , basic question.

i using #import <addressbook/addressbook.h> contact info of device , had implemented same.

everythings work fine when got 1 phone no , 1 email each contact. when got multiple phone no's , multiple email getting crash on app. guess not using proper saving method.

so want know how save 1 name string , 1 array of email(different length) , phone no(different length) group contact , same other. not difficult reproduce result later on detail screen

 cferrorref *error = null; abaddressbookref addressbook = abaddressbookcreatewithoptions(null, error); cfarrayref allpeople = abaddressbookcopyarrayofallpeople(addressbook); cfindex numberofpeople = abaddressbookgetpersoncount(addressbook);  for(int = 0; < numberofpeople; i++) {      abrecordref person = cfarraygetvalueatindex( allpeople, );      nsstring *firstname = (__bridge nsstring *)(abrecordcopyvalue(person, kabpersonfirstnameproperty));     nsstring *lastname = (__bridge nsstring *)(abrecordcopyvalue(person, kabpersonlastnameproperty));     [values1 addobject:[nsstring stringwithformat:@"%@ %@",firstname,lastname]]; //values1 array save name of contact      abmultivalueref emails = abrecordcopyvalue(person, kabpersonemailproperty);     (cfindex j=0; j < abmultivaluegetcount(emails); j++) {         nsstring* email = (__bridge nsstring*)abmultivaluecopyvalueatindex(emails, j);         nslog(@"email:%@", email);         [values2 addobject:[nsstring stringwithformat:@"%@",email]];     } //values2 array save email associated contact      abmultivalueref phonenumbers = abrecordcopyvalue(person, kabpersonphoneproperty);      (cfindex = 0; < abmultivaluegetcount(phonenumbers); i++) {         nsstring *phonenumber = (__bridge_transfer nsstring *) abmultivaluecopyvalueatindex(phonenumbers, i);         nslog(@"phone:%@", phonenumber);         [values3 addobject:[nsstring stringwithformat:@"%@",phonenumber]];     }//values3 array save different phone no's associated contacts       nsdictionary *dict = [[nsdictionary alloc]init];         } 

as have 3 array details contain details of 1 contact. how can merge these 3 array values 1 easy save , fetch data multiples or hundreds of contacts

abaddressbookref allpeople = abaddressbookcreate(); cfarrayref allcontacts = abaddressbookcopyarrayofallpeople(allpeople); cfindex numberofcontacts  = abaddressbookgetpersoncount(allpeople);  nslog(@"numberofcontacts------------------------------------%ld",numberofcontacts);   for(int = 0; < numberofcontacts; i++){     nsstring* name = @"";     nsstring* phone = @"";     nsstring* email = @"";      abrecordref aperson = cfarraygetvalueatindex(allcontacts, i);     abmultivalueref fnameproperty = abrecordcopyvalue(aperson, kabpersonfirstnameproperty);     abmultivalueref lnameproperty = abrecordcopyvalue(aperson, kabpersonlastnameproperty);      abmultivalueref phoneproperty = abrecordcopyvalue(aperson, kabpersonphoneproperty);\     abmultivalueref emailproperty = abrecordcopyvalue(aperson, kabpersonemailproperty);      nsarray *emailarray = (__bridge nsarray *)abmultivaluecopyarrayofallvalues(emailproperty);     nsarray *phonearray = (__bridge nsarray *)abmultivaluecopyarrayofallvalues(phoneproperty);       if (fnameproperty != nil) {         name = [nsstring stringwithformat:@"%@", fnameproperty];     }     if (lnameproperty != nil) {         name = [name stringbyappendingstring:[nsstring stringwithformat:@" %@", lnameproperty]];     }      if ([phonearray count] > 0) {         if ([phonearray count] > 1) {             (int = 0; < [phonearray count]; i++) {                 phone = [phone stringbyappendingstring:[nsstring stringwithformat:@"%@\n", [phonearray objectatindex:i]]];             }         }else {             phone = [nsstring stringwithformat:@"%@", [phonearray objectatindex:0]];         }     }      if ([emailarray count] > 0) {         if ([emailarray count] > 1) {             (int = 0; < [emailarray count]; i++) {                 email = [email stringbyappendingstring:[nsstring stringwithformat:@"%@\n", [emailarray objectatindex:i]]];             }         }else {             email = [nsstring stringwithformat:@"%@", [emailarray objectatindex:0]];         }     }      nslog(@"name : %@",name);     nslog(@"phone: %@",phone);     nslog(@"email: %@",email);     nslog(@"\n"); } 

you can see multiple contact , email in log if contact have.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -