How to get a CNContact phone number(s) as string in Swift?

后端 未结 10 1795
执念已碎
执念已碎 2020-12-13 13:31

I am attempting to retrieve the names and phone number(s) of all contacts and put them into arrays with Swift in iOS. I have made it this far:



        
10条回答
  •  醉话见心
    2020-12-13 14:03

    Here is how you do it in swift 4

    func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) {
    
        if let phoneNo = contactProperty.value as? CNPhoneNumber{
            txtPhone.text = phoneNo.stringValue
        }else{
            txtPhone.text=""
        }
    }
    

提交回复
热议问题