If you just want to get the personβs name, you can do this:
-(IBAction)btnGetContact{ ABPeoplePickerNavigationController *personPicker = [ABPeoplePickerNavigationController new]; personPicker.peoplePickerDelegate = self; [self presentViewController:personPicker animated:YES completion:nil]; } -(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ NSString *firstName; NSString *middleName; NSString *lastName; UIImage *retrievedImage;
But if you want to go to the details of the person to get the numbers of people, you should use BOOL instead of void for peoplePickerNavigationController and pass YES , as shown below:
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ return YES; } -(void) peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{ ABMutableMultiValueRef phoneno = ABRecordCopyValue(person, kABPersonPhoneProperty); CFStringRef phone = ABMultiValueCopyValueAtIndex(phoneno, identifier); _mPhone.text = (__bridge NSString *)phone; [self dismissViewControllerAnimated:NO completion:^(){}]; }
Also remember to import AddressBook.framework and AddressBookUI.framework into your project and ABPeoplePickerNavigationControllerDelegate ,
#import <AddressBook/AddressBook.h> #import <AddressBookUI/AddressBookUI.h>
to the header file.
source share