如何在iPhone的通讯录中选择特定字段 [英] How to select particular field in address book in iPhone

查看:47
本文介绍了如何在iPhone的通讯录中选择特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,必须打开通讯录,我已经使用ABPeoplePickerNavigationController打开通讯录,并且已经为所有用户存储了电话号码和电子邮件,但是我不知道该怎么做.存储电话号码或电子邮件的值,假设用户单击电子邮件字段时,电子邮件地址存储在某个变量中,而单击电话号码存储在另一个变量中.

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......

您可以从iPhone通讯录中获取名字,姓氏,人像和MobileNumber

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

将Button添加到您的ViewController中,并将此代码添加到您的button click事件中.

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

这篇关于如何在iPhone的通讯录中选择特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆