get a phone number based on name of user from iphone address book

Discussion in 'iOS Programming' started by ranjeet, Sep 21, 2010.

  1. ranjeet macrumors newbie

    Joined:
    Sep 21, 2010
    #1
    i am totally new to this topic and searched on this but still very confused please help i need to get a phone number from user's address book based on the name user entered in a text field ....

    please provide any tutorial based on this (if possible)
     
  2. saving107 macrumors 603

    saving107

    Joined:
    Oct 14, 2007
    Location:
    San Jose, Ca
    #2
    more details, please.

    what Use's address book and what text field?
     
  3. ranjeet thread starter macrumors newbie

    Joined:
    Sep 21, 2010
    #3
    reply

    i mean in an app. user types a name in textField and by clicking on find button if there is any entry matched to that name in user's contacts list then the corresponding numbers will be displayed in a label
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    The code in the first post in this thread should give you a good pointer. With the documentation and that I cannot see why you cannot do what you want.
     
  5. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #5
    This lets you search for a person by name. It will then load the person into a PersonView on whether or not they exist. You can specify what items you see or you can get just a specific property back. Don't forget that phone numbers a a multivalueref that will return a CFArray.

    Code:
    -(void)showPersonViewController
    {
        // Fetch the address book 
        ABAddressBookRef addressBook = ABAddressBookCreate();
        // Search for the person named "Appleseed" in the address book
        NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(addressBook, CFSTR("Appleseed"));
        // Display "Appleseed" information if found in the address book 
        if ((people != nil) && [people count])
        {
            ABRecordRef person = (ABRecordRef)[people objectAtIndex:0];
            ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
            picker.personViewDelegate = self;
            picker.displayedPerson = person;
            // Allow users to edit the person’s information
            picker.allowsEditing = YES;
            [self.navigationController pushViewController:picker animated:YES];
        }
        else 
        {
            // Show an alert if "Appleseed" is not in Contacts
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                                            message:@"Could not find Appleseed in the Contacts application" 
                                                           delegate:nil 
                                                  cancelButtonTitle:@"Cancel" 
                                                  otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
        
        [people release];
        CFRelease(addressBook);
    }
     
  6. ranjeet thread starter macrumors newbie

    Joined:
    Sep 21, 2010
    #6
    thank you



    thank you it really hel:)ped....
     

Share This Page