CNContactViewController ignores allowsActions

274 Views Asked by At

CNContactViewController ignores allowsActions. SMS and Mail actions are offered:

enter image description here

with contactVC.allowsActions = false.


I setup CNContactViewController in viewDidLoad():

...
let newContact = CNMutableContact()
newContact.emailAddresses.append(CNLabeledValue(label: CNLabelHome, value: "[email protected]" as NSString))
contactVC = CNContactViewController(forUnknownContact: newContact)
guard let contactVC = contactVC else {
    return
}
contactVC.contactStore = CNContactStore()
contactVC.delegate = self
contactVC.allowsActions = false
...

Why does CNContactViewController show actions with contactVC.allowsActions = false?

2

There are 2 best solutions below

3
On

The dynamic button bar is not controlled by this setting. (Some have commented elsewhere they were added after iOS 9, when this framework was added).

This setting controls the label-style buttons that appear at the bottom of the sheet.

in iOS 11

Enabled:

  • FaceTime row (after phone number, not available in simulator)
  • Send Message
  • Share Contact
  • Share My Location

Everything else is the same.

Checked with initializers "for:" and "forUnknownContact:"

No idea for previous versions, I started in iOS 11...

allowsActions = false

allowsActions = true

3
On

The AllowsActions property does nothing for me too. My best guess is that Apple forgot to support the property when they updated that view controller in newer versions of iOS (it looks quite a bit different now than it did in iOS 9 when the Contacts framework was first released). If anyone has figured out a way to make it work, or to hide that UI, please share.