简体   繁体   English

如何在Swift中使用ABPeoplePickerNavigationController选择多个联系人

[英]how to select multiple contacts with ABPeoplePickerNavigationController in Swift

I have added the ABPeoplePickerNavigationController into my first view controller. 我已将ABPeoplePickerNavigationController添加到我的第一个视图控制器中。 I want that to select multiple contacts from address book then, retrieve their numbers, but my code only selects single person and get its number then, picker disappears. 我希望从通讯录中选择多个联系人,然后检索其电话号码,但是我的代码仅选择一个人并获取其电话号码,选择器消失了。

//instantiate the person picker
    let personPicker: ABPeoplePickerNavigationController

    required init(coder aDecoder: NSCoder) {
        personPicker = ABPeoplePickerNavigationController()
        super.init(coder: aDecoder)
        personPicker.peoplePickerDelegate = self
    }


    @IBAction func getSinglePerson(sender: AnyObject) {
        self.presentViewController(personPicker, animated: true, completion: nil)
    }


    //later, you have handle cancel button properly.
    func peoplePickerNavigationControllerDidCancel(peoplePicker: ABPeoplePickerNavigationController!) {
    }

    func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!) {
        if peoplePicker != personPicker{
            return
        }

        let unmanagedPhones = ABRecordCopyValue(person, kABPersonPhoneProperty)
        let phones: ABMultiValueRef = Unmanaged.fromOpaque(unmanagedPhones.toOpaque()).takeUnretainedValue() as NSObject as ABMultiValueRef

        let countOfPhones = ABMultiValueGetCount(phones)

        for index in 0..<countOfPhones{
            let unmanagedPhone = ABMultiValueCopyValueAtIndex(phones, index)
            let phone: String = Unmanaged.fromOpaque(unmanagedPhone.toOpaque()).takeUnretainedValue() as NSObject as String

            println(phone)
        }

}

Any help is appreciated. 任何帮助表示赞赏。 Thank you! 谢谢!

It's not supported by the built in controller. 内置控制器不支持它。 Try this: https://github.com/tristanhimmelman/THContactPicker 试试这个: https : //github.com/tristanhimmelman/THContactPicker

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用ABPeoplePickerNavigationController在通讯簿中选择多个条目 - How to select multiple entries in address book using ABPeoplePickerNavigationController 如何启动仅包含手机号码的联系人的ABPeoplePickerNavigationController? - How to launch an ABPeoplePickerNavigationController of only contacts that have mobile numbers? ABPeoplePickerNavigationController问题。 如何仅显示带有电子邮件的联系人? - ABPeoplePickerNavigationController issue. How to show only contacts with emails? 如何告诉ABPeoplePickerNavigationController仅列出具有电子邮件地址的联系人? - How to tell ABPeoplePickerNavigationController to list only contacts that have an email address? iOS 8 ABPeoplePickerNavigationController多项选择 - iOS 8 ABPeoplePickerNavigationController Multiple Selection 通过ABPeoplePickerNavigationController“所有联系人”标题的自定义文本 - Custom text over ABPeoplePickerNavigationController “All Contacts” header Swift:从Closing中阻止ABPeoplePickerNavigationController - Swift: Prevent ABPeoplePickerNavigationController from Closing 如何使用 Contacts with Swift 对联系人进行排序 - How to sort contacts using Contacts with Swift ABPeoplePickerNavigationController。 需要在同一视图控制器中显示联系人 - ABPeoplePickerNavigationController. Need to show contacts in the same view controller 快速从ABPeoplePickerNavigationController创建Vcf文件 - Create Vcf file from ABPeoplePickerNavigationController in swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM