objective c - Problem with the duplicate values picking from Address book in Iphone sdk -


here had problem adding contact address book , checking whether in favourites list or not.if not adding contact favourite list.

  - (bool)peoplepickernavigationcontroller:(abpeoplepickernavigationcontroller *)peoplepicker shouldcontinueafterselectingperson:(abrecordref)person property:(abpropertyid)property identifier:(abmultivalueidentifier)identifier   {  contactdto* dtoobject = [[contactdto alloc] init];  abrecordid personid = abrecordgetrecordid(person); nsstring* personidstr = [nsstring stringwithformat:@"%d", personid]; dtoobject.contactid = personidstr;  nsstring *lastnamestring, *firstnamestring;  firstnamestring = [self getvalueforproperty:kabpersonfirstnameproperty forcontact:personidstr]; lastnamestring = [self getvalueforproperty:kabpersonlastnameproperty forcontact:personidstr];  dtoobject.firstname =  firstnamestring; dtoobject.lastname =  lastnamestring;  printf("\n *****************firstnamestring %s",[firstnamestring utf8string]); //abmultivalueref emailmultivalue =[(nsstring *)abrecordcopyvalue(person, kabpersonemailproperty) autorelease];  abmultivalueref phonemultivalue =[(nsstring *)abrecordcopyvalue(person, kabpersonphoneproperty) autorelease]; if (abmultivaluegetcount(phonemultivalue) > 0) {     abmultivalueref phonemultivalue =[(nsstring *)abrecordcopyvalue(person, kabpersonphoneproperty) autorelease];      nsstring* curenttypelabel =[(nsstring *)abmultivaluecopylabelatindex(phonemultivalue,identifier) autorelease];     curenttypelabel = [curenttypelabel stringbyreplacingoccurrencesofstring:@"_$!<" withstring:@""];     curenttypelabel = [curenttypelabel stringbyreplacingoccurrencesofstring:@">!$_" withstring:@""];      dtoobject.numbertype = curenttypelabel;      nsstring* currentphone = [(nsstring *)abmultivaluecopyvalueatindex(phonemultivalue,identifier) autorelease];     dtoobject.mobnumber = currentphone;       favoritesappdelegate* appdelegate = (favoritesappdelegate*) [[uiapplication sharedapplication] delegate];      if ([favoritesarray count] > 0)     {         (int i=0; i< [favoritesarray count]; i++)         {              contactdto* dtoobject1 = [favoritesarray objectatindex:i];             printf("\n dtoobject1.contactid value = %s,   main value = %s",[dtoobject.firstname utf8string],[dtoobject1.firstname utf8string]);             printf("\n dtoobject1.mobnumber value = %s,  main mobnumber value = %s",[dtoobject1.mobnumber utf8string],[dtoobject.mobnumber utf8string]);             if ([dtoobject.firstname isequaltostring:dtoobject1.firstname])             {                  printf("\n inside if....");             }             else             {                 [appdelegate addcontacttofavorites:dtoobject];                 break;                 printf("\n inside else....");              }          }     }     else     {         [appdelegate addcontacttofavorites:dtoobject];     }      [self dismissmodalviewcontrolleranimated:yes];  } /*else if(abmultivaluegetcount(emailmultivalue) > 0) {     nsstring* currentemail =(nsstring *)abmultivaluecopyvalueatindex(emailmultivalue,identifier);     printf("\n *************currentemail** %s",[currentemail utf8string]);     [self emailbtnaction:currentemail];   }*/ [dtoobject release];  return no;  } 

for code written shown above. eventhough getting duplicate values condition failed , duplicate values added. can give suggestions rid of this? anyone's appreciated.

thanks all, monish.

you adding favorites array if new contact doesn't match 1 of existing items in favorites array. new contact in favorites array further along in array. need check if new contact doesn't match of existing favorites.

also, shouldn't match condition more checking first names?

something this:

bool contactalreadyexists = no; (int i=0; i< [favoritesarray count]; i++) {   contactdto* dtoobject1 = [favoritesarray objectatindex:i];   if ([dtoobject.firstname isequaltostring:dtoobject1.firstname])   {     contactalreadyexists = yes;     break;   } } if (!contactalreadyexists) {   [appdelegate addcontacttofavorites:dtoobject]; } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -