Swiftpack.co -  dragosrobertn/KNContactsPicker as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
dragosrobertn/KNContactsPicker
A modern, highly customisable contact picker with search and multi-selection options.
.package(url: "https://github.com/dragosrobertn/KNContactsPicker.git", from: "push")

KNContactsPicker

CocoaPods codebeat badge contributions

A modern, highly customisable contact picker with multi-selection options that closely resembles the behaviour of the ContactsUI's CNContactPickerViewController.

Preview

Single Deselect Mode Single Reselect Mode Multiple Select Mode
Single Deselect Single Reselect Multi Select

Installation

CocoaPods

Add this to your podfile for the latest version

pod 'KNContactsPicker'

Or specify desired version

pod 'KNContactsPicker', '~> 0.3'

Manual Installation

Download and include the KNContactsPicker folder and files in your codebase.

Requirements

  • iOS 12+
  • Swift 5

Features

KNContactsPicker is a modern, customisable and easy to use Contacts Picker similar to the stock CNContactPickerViewController. It does improve in a couple of area for a better UX.

  • Three contact selection modes:
    • Single Deselect (Deselects all other contacts after first contact is selected)
    • Single Reselect (Selects another contact on tap)
    • Multi Select
  • Contact images or initials
  • Search contacts and ability to select while searching
  • Clear selection button
  • Contact section indexes to quickly navigate through the contact list
  • Returns CNContact objects
  • Highly customisable settings for strings and options
  • Two conditional methods to enable or deselect certain contacts
  • Support iOS 13
    • Dark Mode
    • Icons (SF Symbols)
    • Pull to Dismiss

Coming soon:

  • Extra contact info under name
  • Contact sort order
  • Contact display order
  • More modular contact property approach

Make sure your app (the host app) has provided a Privacy - Contacts Usage Description in your Info.plist. It's also recommended that you check that contact authorisation is granted.

How to use

Implement the Delegate Methods

// This is in your application
extension ViewController: KNContactPickingDelegate {
    func contactPicker(didFailPicking error: Error) {
        print(error)
    }
    func contactPicker(didCancel error: Error) {
         print(error)
    }
    func contactPicker(didSelect contact: CNContact) {
        self.contacts.append(contact)
        self.contactsTableView.reloadData()
    }
    
    func contactPicker(didSelect contacts: [CNContact]) {
        self.contacts.append(contentsOf: contacts)
        self.contactsTableView.reloadData()
    }
}

Customise the Settings

var settings = KNPickerSettings()
settings.pickerTitle = "Pick"

settings.conditionToDisplayContact = { contact in
  return contact.organizationName == "Apple"
}
settings.conditionToDisableContact = { contact in
    return self.contacts.contains(contact)
}

Initialise and Present the KNContactsPicker

let controller = KNContactsPicker(delegate: self, settings: settings)
        
self.navigationController?.present(controller, animated: true, completion: nil)

Recommended

You can use KNContactsPicker with KNContacts framework.

GitHub

link
Stars: 11
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

v0.3.0 - Support for Swift Package Manager, Select All contacts button
1 week ago

This releases adds support for SPM. In addition it adds a new option to select all displaying contacts with a Select all button.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API