Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3212896
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:53:09+00:00 2026-05-17T14:53:09+00:00

Here I had a problem that I am adding contact from the address book

  • 0

Here I had a problem that I am adding contact from the address book and checking it whether it is already in the favourites list or not.If not I am adding the contact to 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)
    {
        for (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 that the code I written was shown as above.
Eventhough I am getting the duplicate values the condition is failed and duplicate values are added.
Can anyone give suggestions to get rid of this?
Anyone’s help will be much appreciated.

Thanks to all,
Monish.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:53:09+00:00Added an answer on May 17, 2026 at 2:53 pm

    You are adding to favorites array if the new contact doesn’t match ONE of the existing items in the favorites array. But the new contact could be in the favorites array further along in the array. You need to check if the new contact doesn’t match ALL of the existing favorites.

    Also, shouldn’t the match condition be more than just checking first names?

    Something like this:

    BOOL contactAlreadyExists = NO;
    for (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];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've had an ongoing need here that I can't figure out how to address
I was wondering if anyone here had some experience writing this type of script
We had a discussion here at work regarding why fread() and fwrite() take a
I had a similar question answered Here There is a slight twist to the
yesterday you had taught me to query record history within a time range here
What memory leak detectors have people had a good experience with? Here is a
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.