可以将CNContactPickerViewController添加为子视图控制器吗?

时间:2016-02-25 21:51:41

标签: ios abaddressbook cncontactviewcontroller

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

0 个答案:

没有答案