我如何将所有联系人的 phone 号码编译到一个单元格中 - 使用 CNContact
How do i compile all contact's phone numbers into one cell - using CNContact
我用来获取联系人 phone 号码的代码如下,我想做的是将所有联系人 phone 号码(固定电话、手机等)一起显示,示例0402 000 000、618 802336、0423 000 000(一起在一个文本字段中)
下面是我的代码
// Retrieve contact details ---------------------------
@IBAction func show(_ sender: Any) {
let contacVC = CNContactPickerViewController()
contacVC.delegate = self
self.present(contacVC, animated: true, completion: nil)
}
func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
print(contact.phoneNumbers)
let numbers = contact.phoneNumbers.first
print((numbers?.value)?.stringValue ?? "")
self.Phone.text = "\((numbers?.value)?.stringValue ?? "")"
}
func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
self.dismiss(animated: true, completion: nil)
}
您可以显示所有 phone 个号码,如下所示
let contact = CNContact()
let numbers = contact.phoneNumbers.compactMap { [=10=].value.stringValue }
self.Phone.text = numbers.joined(separator: ", ")
我用来获取联系人 phone 号码的代码如下,我想做的是将所有联系人 phone 号码(固定电话、手机等)一起显示,示例0402 000 000、618 802336、0423 000 000(一起在一个文本字段中)
下面是我的代码
// Retrieve contact details ---------------------------
@IBAction func show(_ sender: Any) {
let contacVC = CNContactPickerViewController()
contacVC.delegate = self
self.present(contacVC, animated: true, completion: nil)
}
func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
print(contact.phoneNumbers)
let numbers = contact.phoneNumbers.first
print((numbers?.value)?.stringValue ?? "")
self.Phone.text = "\((numbers?.value)?.stringValue ?? "")"
}
func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
self.dismiss(animated: true, completion: nil)
}
您可以显示所有 phone 个号码,如下所示
let contact = CNContact()
let numbers = contact.phoneNumbers.compactMap { [=10=].value.stringValue }
self.Phone.text = numbers.joined(separator: ", ")