从CNContactPicker中的单个联系人中选择多个属性 [英] select multiple properties from single contact in CNContactPicker

查看:267
本文介绍了从CNContactPicker中的单个联系人中选择多个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CNContactPickerViewController并一直遇到有关如何从单个联系人中选择多个属性的问题

I am trying to use the CNContactPickerViewController and keep running into issues with how to pick multiple properties from a single contact

选择器的基本显示

    let contactStore = CNContactStore()

override func viewDidLoad() {
    super.viewDidLoad()

    self.askForContactAccess()
    self.displayContacts()
}

func displayContacts(){
    let contactPicker = CNContactPickerViewController()
    contactPicker.delegate = self
    self.present(contactPicker, animated: true, completion: nil)
}

这将在用户授予权限后显示地址簿(代码在上面,但上面没有显示)

this displays the address book after the user gives permission(the code is there but didn't show it above)

现在我想做的是当用户选择一个联系人时,我们导航到联系人详细信息视图(当前发生这种情况),但是当我尝试使用代理人时

Now what I would like to do is when the user selects a contact we navigate into the contact details view(this happens currently) but when I try to use the delegate

func contactPicker(_ picker: CNContactPickerViewController, didSelectContactProperties contactProperties: [CNContactProperty])

我看到了联系人选择器视图,可以在其中选择多个联系人.我不介意扩展联系人详细信息视图,以便可以选择多个属性,但我什至不知道如何将其连接.

I get presented with the contact picker view where I can select multiple contacts. I don't mind trying to extend the contact detail view so that I can select multiple properties but I don't even know how to hook into it.

我可以创建一个完全自定义表格视图,然后在此处选择属性,但是由于苹果创建了一个很好的联系人详细信息视图,所以我宁愿使用它.

I can create a completely custom table view and select the properties there but since apple created a nice contact detail view I would rather use that.

推荐答案

tl; dr -不,您不能使用CNContactPickerViewController从一个联系人中选择多个属性.

tl;dr - No, you can't use CNContactPickerViewController to select multiple properties from one contact.

完整版本:

CNContactPickerViewController的实现不当且令人困惑.

CNContactPickerViewController is poorly and confusingly implemented.

实际上,它实际上不支持从单个联系人中选择多个属性的功能.选择单个联系人属性后,选择器将自动关闭.

It in fact does not actually support the ability to select multiple properties from a single contact. The picker is automatically dismissed after selecting a single contact property.

实际上,它不允许用户从多个联系人中选择特定属性.

It does not actually let the user select specific properties from multiple contacts.

它支持以下内容:

  • 选择一个联系人
  • 选择单个联系人的单个属性
  • 选择多个联系人
  • 选择多个联系人,然后从每个用户选择的多个联系人中返回一个预定的(不是用户选择的)属性.

要使didSelectContactProperties委托以除空的属性列表以外的任何方式被调用,必须将predicateForSelectionOfProperty属性设置为一个谓词,该谓词指定一个且仅一个联系人属性键.如果您提供任何其他谓词,则在点击联系人时会出现黑屏,并且您的应用程序现在已挂起,需要杀死.

To get the didSelectContactProperties delegate to be called with anything other than an empty list of properties, you must set the predicateForSelectionOfProperty property to a predicate that specifies one and only one contact property key. If you provide any other predicate, the get a black screen when you tap on a contact and your app is now hung and needs to be killed.

我相信存在多个与选择多个联系人的联系人属性相关的错误.

I believe there are several bugs associated with picking contact properties of multiple contacts.

解决方法:

我相信唯一的解决方案(除了在Contacts框架周围您自己完整的自定义视图控制器之外)将通过在单个联系人选择模式下组合CNContactPickerViewController并随后使用CNContactViewController显示所选联系人的详细信息.然后实现contactViewController(_:shouldPerformDefaultActionFor:)委托方法以跟踪用户选择的属性.

I believe the only solution (besides your own complete custom view controllers around the Contacts framework) would be to make your own multiple property selection by combining CNContactPickerViewController in single contact selection mode, followed by using CNContactViewController to display the details of the selected contact. Then implement the contactViewController(_:shouldPerformDefaultActionFor:) delegate method to keep track of the properties chosen by the user.

这篇关于从CNContactPicker中的单个联系人中选择多个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆