In iOS 9, the Contacts framework replaced AddressBook.framework as the suggested way to interact with that data. Today we'll check out a library called EPContactsPicker, which is built on top of the Contacts framework and encapsulates a lot of the boilerplate logic. Let's dive in.
let contactPickerVC = EPContactsPicker(
delegate: self,
multiSelection: true,
subtitleCellType: SubtitleCellValue.Email
)
let nc = UINavigationController(rootViewController: contactPickerVC)
presentViewController(nc, animated: true, completion: nil)
Pretty simple! We can add a delegate function to grab the contact or contacts that were selected:
func epContactPicker(_: EPContactsPicker, didSelectMultipleContacts contacts: [EPContact]) {
for contact in contacts {
print("\(contact.displayName())")
}
}
More info about EPContactsPicker can be found at git.io/contactspicker