user748001
user748001

Reputation: 181

How to select particular field in address book in iPhone

i am working on one app and in that i have to open the address book, i have used ABPeoplePickerNavigationController to open address book and in that have stored phone number and email for all the user, however i didnd't know how to store the value of phone number or email, suppose if user clicks on email field the email address stores in some variable and if clicks on phone number store in another variable.

Upvotes: 0

Views: 484

Answers (1)

Mehul Mistri
Mehul Mistri

Reputation: 15147

Hello Please find the code below......

You can get FirstName,LastName ,Image of the person and MobileNumber from your iPhone addressbook

Add Button to your ViewController and add this code to your button click event.

-(IBAction)btnGetNameClicked:(id)sender {
      // creating the picker
     ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
     // place the delegate of the picker to the controll
     picker.peoplePickerDelegate = self;

     // showing the picker
     [self presentModalViewController:picker animated:YES];
    // releasing
    [picker release];
 }

 -(BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

     // setting the first name
     lblFirstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

     // setting the last name
     lblLastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);   

    ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
    lblNumber.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
    if(ABPersonHasImageData(person)){
         imgPerson.image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(person)];
    } else {
         imgPerson.image = [UIImage imageNamed:@"NotAvailable.png"];
    }

    // remove the controller
    [self dismissModalViewControllerAnimated:YES];

    return NO;
 }

Upvotes: 2

Related Questions