[英]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.