Show The Contact List in Swift

The ContactUI framework provide the controllers for displaying, editing,  selecting and creating the contacts from your app.

This tutorial provide only to display contact from your contact apps. In ContactUI framework have a controller "CNContactPickerViewController", Which fetch all contact from your contact App. 

Follow the below steps for Display contact using  CNContactPickerViewController.

Step 1 : Import ContactUI framework in Swift file.
import ContactsUI
Step 2 : Add the CNContectPickerDelegate in Swift file.
class ViewController: UIViewController , CNContactPickerDelegate {
Step 3 : Add a Button, to present CNContactPickerViewController to display all concats.
@IBAction func click_Contact(sender: AnyObject) {
    let cnPicker = CNContactPickerViewController()
    cnPicker.delegate = self
    self.presentViewController(cnPicker, animated: true, completion: nil)
Step 4 : The below method of CNContectPickerDelegate.
//MARK:- CNContactPickerDelegate Method

func contactPicker(picker: CNContactPickerViewController, didSelectContacts contacts: [CNContact]){
    contacts.forEach { contact in
        for number in contact.phoneNumbers {
            let phoneNumber = number.value as! CNPhoneNumber
            print("number is = \(phoneNumber)")

func contactPickerDidCancel(picker: CNContactPickerViewController){
    print("Cancel Contact Picker")

See  Output :


Show The Contact List in Swift Show The Contact List in Swift Reviewed by Kirit Modi on 01:48:00 Rating: 5

No comments:

Powered by Blogger.