Try this way...
视图控制器.h
#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
@interface ViewController : UIViewController
<ABPeoplePickerNavigationControllerDelegate>
@property (nonatomic, retain) ABPeoplePickerNavigationController *contacts;
-(IBAction)btn_press:(id)sender;
@end
视图控制器.m
-(IBAction)btn_press:(id)sender
{
contacts = [[ABPeoplePickerNavigationController alloc] init];
// Set the delegate.
[contacts setPeoplePickerDelegate:self];
[contacts setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]]];
[self presentViewController:contacts animated:YES completion:nil];
}
#pragma mark - AddressBook Delegate Methods
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
return YES;
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
NSString *firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
ABMutableMultiValueRef phoneno = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *phone;
phone = (__bridge NSString *)ABMultiValueCopyValueAtIndex(phoneno, 0);
NSLog(@"%@",phone); // Prints 0413588266
**** NEW Update for Dismiss the Picker*******
[contacts dismissViewControllerAnimated:NO completion:nil];
return NO:
}
如果您有任何问题,请告诉我。