作者:Love@YR
鏈接:http://blog.csdn.net/jingqiu880905/article/details/51074409
請尊重原創,謝謝!
iOS8及以前的通訊錄框架是AddressBookUI
9之後改了ContactsUI
代碼如下:
#import <AddressBookUI/ABPeoplePickerNavigationController.h>
#import <ContactsUI/CNContactPickerViewController.h>
#import <AddressBook/AddressBook.h>
#import <Contacts/Contacts.h>
if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
CNContactPickerViewController *picker=[[CNContactPickerViewController alloc]init];
picker.delegate=self;
[self.h5ViewController presentViewController:picker animated:YES completion:NULL];
}
else
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self.h5ViewController presentViewController:picker animated:YES completion:NULL];
}
其中如果實現了- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContacts:(NSArray<CNContact*> *)contacts
或者- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperties:(NSArray<CNContactProperty*> *)contactProperties
就會默認通訊錄多選,所以如果想要pickerView展現的是單選,就不要實現這兩個delegate協議方法即可。