我想添加CNContactPickerViewController
一个UITabBarController
标签。我用ABPeoplePickerNavigationController
同样的方法实现了同样的目标,但对CNContactPickerViewController
. 有什么我错过的还是不可能的。
这是我尝试过的:
注意:当我删除它时if #available(iOS 9, *)
,它也适用于 iOS 9。
class ContactsViewController: UIViewController, ABPeoplePickerNavigationControllerDelegate, CNContactPickerDelegate {
var contactsController: UIViewController!
override func awakeFromNib() {
contactsController = getAddressBook()
contactsController.view.frame = self.view.bounds
self.addChildViewController(contactsController)
contactsController.didMoveToParentViewController(self)
}
override func viewDidLoad() {
super.viewDidLoad()
self.contactsController.view.frame = self.view.bounds
self.view.addSubview(contactsController.view)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func getAddressBook() -> UIViewController {
if #available(iOS 9, *) {
let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self;
contactPicker.displayedPropertyKeys = [CNContactPhoneNumbersKey]
return contactPicker
} else {
let addressBookController = ABPeoplePickerNavigationController()
addressBookController.peoplePickerDelegate = self
return addressBookController
}
}
}