Is it possible to disable message, call, mail etc options from contact List using Address Book Api
I just want user can select only address from contact list.
For reference please check below marked option on image.
Is it possible to disable message, call, mail etc options from contact List using Address Book Api
I just want user can select only address from contact list.
For reference please check below marked option on image.
There is CNContact property keys to display in the contact detail card. You can do this by setting displayedPropertyKeys property of CNContactPickerViewController when you showing the contact list:
let contactPicker = CNContactPickerViewController()
contactPicker.displayedPropertyKeys = [CNContactPostalAddressesKey]
If you are showing the contact using CNContactViewController then can disable action using allowsActions property:
let controller = CNContactViewController(for: SELECTED_CONTACT)
controller.contactStore = CNContactStore()
controller.allowsActions = false
controller.delegate = self
Complete implemention:
Function for showing CNContactPickerViewController:
@IBAction func showContactList( sender: Any) ->Void{
let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self
self.present(contactPicker, animated: true, completion: nil)
}
Implement delegate for CNContactPickerViewController:
public func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact){
print(#function)
picker.dismiss(animated: true, completion:{
self.showDetailFor(contact: contact)
})
}
to display details of contact open CNContactViewController:
func showDetailFor(contact: CNContact) -> Void{
let contactViewController = CNContactViewController(forUnknownContact: contact)
contactViewController.contactStore = CNContactStore()
contactViewController.delegate = self
contactViewController.allowsActions = false
self.navigationController?.pushViewController(contactViewController, animated: true)
}
implement CNContactViewControllerDelegate to get selected property or handle action for any property:
func contactViewController(_ viewController: CNContactViewController,
shouldPerformDefaultActionFor property: CNContactProperty) -> Bool{
// return true if want to perform any action on selected property otherwise return false
return false
}