gpt4 book ai didi

swift - 联系人有多个邮件时的 CNContactPickerViewController

转载 作者:可可西里 更新时间:2023-11-01 00:55:19 34 4
gpt4 key购买 nike

我正在使用 CNContactPickerViewController 让用户选择他/她的联系人之一的电子邮件

let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self
contactPicker.predicateForSelectionOfContact = NSPredicate(format: "emailAddresses.@count > 0")
contactPicker.displayedPropertyKeys = [CNContactNicknameKey, CNContactEmailAddressesKey]

当联系人只有一封邮件时,一切顺利

func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {

if let _mail = contact.emailAddresses.first?.value as String? {
self.personWasSelected(with: _mail)
}
}

但有时其中一个联系人有不止一封邮件,我如何让用户选择其中一封?

最佳答案

好的,通过试错找到了解决方案......

我同时实现了:

func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) {
if let _mail = contactProperty.value as? String {
self.personWasSelected(with: _mail)
}
}

func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {

if let _mail = contact.emailAddresses.first?.value as String? {
self.personWasSelected(with: _mail)
}
}

但是只有第一个应该已经实现了

关于swift - 联系人有多个邮件时的 CNContactPickerViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50683291/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com