Addressbookui. framework, which is a system framework with its own UI interface, requires user authorization for the first access. Because it’s already packaged, it’s easy to use

  1. Import the framework#import <AddressBookUI/AddressBookUI.h>
  2. Creating a Controller
ABPeoplePickerNavigationController *Vc = [[ABPeoplePickerNavigationController alloc] init];
Copy the code
  1. Set the controller as the agent, and monitor the user’s click operation after the communication record controller pops up
Vc.peoplePickerDelegate = self;
Copy the code
  1. The pop-up
[self presentViewController:Vc animated:YES completion:nil];
Copy the code

ABPeoplePickerNavigationControllerDelegate agency agreement, there are two ways to monitor user click operation method

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person;
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person  property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierCopy the code

The difference between these two methods lies in: the first method is to listen to the user click a contact will be called, and automatically close the page; The second is that after clicking a specific contact, it will automatically jump to the details page of the corresponding contact. When clicking on specific properties, it will be called. This method will pass the property value and get the value to obtain some specific information. After clicking the Cancel button in the upper right corner, the modal interface is closed and the Cancel method is called

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
Copy the code

The above effects are tested on iOS9.2 simulator

In order to test the real machine, I changed the deployment version to iOS7.1 and ran it on my 4S master machine, and found that the two methods were not called and the controller from Modal could not be shut down =.=

Google and found the original – (void) peoplePickerNavigationController: peoplePicker didSelectPerson: and… (void)peoplePickerNavigationController:peoplePicker didSelectPerson: property: Identifier: these two methods are only useful since iOS8, and iOS7 and before were used to use – (BOOL) peoplePickerNavigationController: shouldContinueAfterSelectingPerson: and… (BOOL) peoplePickerNavigationController: shouldContinueAfterSelectingPerson: property: identifier: these two methods, two methods are similar, and after iOS8 iOS only It expires after 8. So these two outdated methods are necessary if you want to adapt to lower versions. At the same time – (void) in iOS7 peoplePickerNavigationControllerDidCancel: popup controller methods are to be manually. After iOS8 will automatically pop up, so in order to adaptation, ensure that iOS7 – iOS9 are effective, manually dismiss It off.

### Refer to iOS access address book development to read contact information