Get phone contacts

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/WangErice/article/details/51558367

Get phone contacts and address book functions are more common, due to the acquisition method after iOS8 change, making the acquisition method of time-varying compatibility is not so friendly, the paper obtain individual contact method and complete address book a simple package, and obtaining a single contact for selecting contacts.

Note: The method described is only compatible for after iOS7.0, also be noted that unless there are special needs, do not easily hidden obtain the user's address book, but can not leak the user's personal information.

1) In order to maintain the function to achieve independence, to avoid unnecessary external dependencies, we create a Category to reality UIWindow obtain application controller is currently being displayed, and then use the controller to present it ABPeoplePickerNavigationController object. The main achieve the following, to find the controller is currently being displayed by a simple recursive.


2) the introduction of AddressBook.framework and AddressBookUI.framework two systems framework and related header files in the project, create inherited from the NSObject AddressBookManager address book management class.

The following enumerated type defined to represent the state of the return;


Defined callback function returns


Wherein the code representative of the state of the returned, response representative of the operation result return data.

The method defined in two classes, respectively, for selecting a single and entire address book contacts


3) obtaining a single contact-implemented method


In iOS7 the proxy method to be achieved


In iOS8_OR_LATER need to implement the following delegate method:


For a complete address book of methods to achieve


Want to get detailed implementation details, you can click to download.

Guess you like

Origin blog.csdn.net/WangErice/article/details/51558367