[英]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.