Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contact picker in ios to get phone number

enter image description hereI need an option like image picker for picking contact and to display phone number i have managed to get contact names using below code

by using this code it only returns the names , need an option to pick contact from contact list

like image 787
Midhun Narayan Avatar asked Aug 20 '18 11:08

Midhun Narayan


People also ask

How do you use contact picker?

Opening the Contact Picker #contacts. select() . When called, it returns a promise and shows the contact picker, allowing the user to select the contact(s) they want to share with the site. After selecting what to share and clicking Done, the promise resolves with an array of contacts selected by the user.

What is contact picker API?

The Contact Picker API allows users to select entries from their contact list and share limited details of the selected entries with a website or application.

How do I find contacts in Swift?

Swift 4 and 5.import ContactsUI func phoneNumberWithContryCode() -> [String] { let contacts = PhoneContacts. getContacts() // here calling the getContacts methods var arrPhoneNumbers = [String]() for contact in contacts { for ContctNumVar: CNLabeledValue in contact. phoneNumbers { if let fulMobNumVar = ContctNumVar.

How do I use contact picker in flutter?

flutter_contact_picker. With this plugin a Flutter app can ask its user to select a contact from his/her address book. The information associated with the contact is returned to the app. This plugin uses the operating system's native UI for selecting contacts and does not require any special permissions from the user.


1 Answers

import ContactsUI
and include - CNContactPickerDelegate

import ContactsUI

class YourViewController: CNContactPickerDelegate{

    //MARK:- contact picker
    func onClickPickContact(){


        let contactPicker = CNContactPickerViewController()
        contactPicker.delegate = self
        contactPicker.displayedPropertyKeys =
            [CNContactGivenNameKey
                , CNContactPhoneNumbersKey]
        self.present(contactPicker, animated: true, completion: nil)

    }

    func contactPicker(_ picker: CNContactPickerViewController,
                       didSelect contactProperty: CNContactProperty) {

    }

    func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
        // You can fetch selected name and number in the following way

        // user name
        let userName:String = contact.givenName

        // user phone number
        let userPhoneNumbers:[CNLabeledValue<CNPhoneNumber>] = contact.phoneNumbers
        let firstPhoneNumber:CNPhoneNumber = userPhoneNumbers[0].value


        // user phone number string
        let primaryPhoneNumberStr:String = firstPhoneNumber.stringValue

        print(primaryPhoneNumberStr)

    }

    func contactPickerDidCancel(_ picker: CNContactPickerViewController) {

    }
}
like image 178
Midhun Narayan Avatar answered Sep 20 '22 23:09

Midhun Narayan