我想在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
}
}
}