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

后端 未结 10 1780
执念已碎
执念已碎 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 13:59

    The definition of a CNLabeledValue:

    The CNLabeledValue class is a thread-safe class that defines an immutable value object that combines a contact property value with a label. For example, a contact phone number could have a label of Home, Work, iPhone, etc.

    CNContact.phoneNumbers is an array of CNLabeledValues and each CNLabeledValue has a label and a value.

    To print the phoneNumbers corresponding to a CNContact you can try:

    for phoneNumber in contact.phoneNumbers {
        print("The \(phoneNumber.label) number of \(contact.givenName) is: \(phoneNumber.value)")
    }
    

提交回复
热议问题