我需要从联系人处获取电话号码.
为此我的代码是
- (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;
}
Run Code Online (Sandbox Code Playgroud)
在这里它像这样显示在控制台中
ABMultiValueRef 0x740b680 with 1 value(s)
0: _$!<Mobile>!$_ (0x7419880) - (929) 230-8622 (0x740b490)
Run Code Online (Sandbox Code Playgroud)
这(929) 230-8622是手机号码,我怎么才能获得手机号码.
选择联系后,我需要关闭此视图控制器.
为此,我写这样的代码
[self dissmissModalViewControllerAnimated:YES];
但它显示,myclass可能无法响应dissmissModalViewController.
如何在选择后我需要关闭此视图控制器.
任何人都可以帮助我.
提前谢谢你.
我使用“通过添加此代码”解决了我的问题。
- (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;
}
Run Code Online (Sandbox Code Playgroud)
希望这对像我这样面临问题的人有所帮助。
| 归档时间: |
|
| 查看次数: |
3216 次 |
| 最近记录: |