简体   繁体   English

如何获取联系人中所选人员的电话号码

[英]how to get phone number of selected person in contacts

I need to get phone number from contacts. 我需要从联系人处获取电话号码。

For that my code is 为此我的代码是

- (IBAction)contacts {

    NSLog(@"contacts clicked ");

    ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
    peoplePickerController.peoplePickerDelegate = self;
    [self presentModalViewController:peoplePickerController animated:NO];
    [peoplePickerController release];

}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    NSString *number = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);

    NSLog(@" %@",number);
    return YES;
}

here it displays in console like this 在这里它像这样显示在控制台中

ABMultiValueRef 0x740b680 with 1 value(s)
    0: _$!<Mobile>!$_ (0x7419880) - (929) 230-8622 (0x740b490)

Here (929) 230-8622 is mobile number,How can i get only mobile number. 这里(929) 230-8622是手机号码,我怎么才能获得手机号码。

After selecting contact i need to close this view controller. 选择联系后,我需要关闭此视图控制器。

For that i write code like this 为此,我写这样的代码

[self dissmissModalViewControllerAnimated:YES]; [self dissmissModalViewControllerAnimated:YES];

But it shows waning that myclass may not respond to dissmissModalViewController. 但它显示,myclass可能无法响应dissmissModalViewController。

How can i done that after selection i need to close this view controller. 如何在选择后我需要关闭此视图控制器。

can anyone pls help me. 任何人都可以帮助我。

Thank u in advance. 提前谢谢你。

I resolve my problem using By Adding this code. 我通过添加此代码解决了我的问题。

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier {
    if (property == kABPersonPhoneProperty) {
        ABMultiValueRef emails = ABRecordCopyValue(person, property);
        CFStringRef phonenumberselected = ABMultiValueCopyValueAtIndex(emails, identifier);
        CFStringRef emailLabelSelected = ABMultiValueCopyLabelAtIndex(emails, identifier);
        CFStringRef emailLabelSelectedLocalized = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(emails, identifier));
        NSLog(@"\n EmailValueSelected = %@ \n EmailLabelSelected = %@ \n \EmailLabeSelectedlLocalized = %@", phonenumberselected, emailLabelSelected, emailLabelSelectedLocalized);

        NSString *aNSString = (NSString *)phonenumberselected;



        [ self dismissModalViewControllerAnimated:YES ];
        return NO;
    }   
    return YES;
}

Hope this helpful who face problem like me. 希望这有助于面对像我这样的问题。

write below code in your 在下面写下代码

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

{       

    ABMultiValueRef mul;
    mul=(NSString *) ABRecordCopyValue(person, kABPersonEmailProperty);
    int count= ABMultiValueGetCount(mul);
    NSString *name=(NSString *) ABMultiValueCopyValueAtIndex(mul,0);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取iPhone联系人电话号码类型 - Get iPhone contacts phone number type 如何仅显示带有电话号码的联系人? - How to display only contacts with phone number? 如何获取地址簿联系人中每个人的姓名和电子邮件 - How to get name and email of every person in address book contacts 检查号码是否在电话联系人中 - checking whether the number is in phone contacts are not 如何获取地址簿中所有联系人带有标签的所有电话号码? - How to get all phone numbers with labels for all contacts in address book? iPhone地址簿:如何获取仅包含电话号码的联系人列表? - iPhone Address Book: How to get a list of only contacts with phone numbers? 我是世界上唯一无法从UIWebView拨打电话的人吗? - Am I the only person in the world that CAN'T get a phone number to dial from a UIWebView? 如何显示所选联系人(从通讯录中选择:ABPickeView)的名称以及文本框中的号码 - How to display the selected contact person (selected from address book: ABPickeView ) name as well along with the number in the text filed iPhone自定义电话如何为电话联系人振铃 - iPhone customization of how phone ringing for phone contacts iPhone中的电话联系人中没有电话号码时,程序崩溃 - program crashes when there is no phone number in phone contacts in iphone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM