开发者

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.


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;
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜