contactPickerDidCancel and contactPicker Functions are never called

cncontactpickerviewcontroller
cncontactpickerviewcontroller swift 4
swift contact picker
swift select contact from address book
fetch contacts swift 4
contacts framework swift 4 tutorial
contactsui
cncontactpickerviewcontroller tutorial

Hello I'm new to iOS design and Swift and I'm trying to implement a simple Contact picker that allows the user to simply select a contact. I have a button in a view controller and the view controller conforms to the CNContactPickerDelegate, but when I run the app and use the picker, my contactPickerDidCancel function and my contactPicker function never get called no matter what I press inside the picker. As far as I understand, the picker should call the functions I wrote when I click not he cancel button or a contact inside the picker. Is this wrong? Any help or ideas would be great! Thanks!

UPDATE: Solved. It was a simple syntax error. In both functions, I didn't put an underscore before "picker".

@IBAction func addContactPressed(_ sender: Any) {

    let contactPickerViewController = CNContactPickerViewController()

    contactPickerViewController.delegate = self

    contactPickerViewController.predicateForEnablingContact = NSPredicate(format: "phoneNumbers.@count > 0", argumentArray: nil)

    contactPickerViewController.predicateForSelectionOfProperty =
        NSPredicate(format: "key == 'phoneNumbers'", argumentArray: nil)

    contactPickerViewController.displayedPropertyKeys = [CNContactEmailAddressesKey, CNContactPhoneNumbersKey]

    self.present(contactPickerViewController, animated: true, completion: nil)

}


func contactPickerDidCancel(picker: CNContactPickerViewController) {
    print("Cancelled picking a contact.")
}

func contactPicker(picker: CNContactPickerViewController, didSelectContact contact: CNContact) {
    print("Selected a contact.")
    if contact.isKeyAvailable(CNContactPhoneNumbersKey) {
        print(contact.phoneNumbers)
    }
    else {
        print("No phone numbers are available.")
    }
}

You have to rewrite CNContactPickerDelegate methods with new signature :

func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
    //handle contact
}

func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
    //handle cancel event
}

Underscore _ will Omitting Argument Labels from methods in new swift syntax. So use new signature.

contactPickerDidCancel(_:), You have to rewrite CNContactPickerDelegate methods with new signature : func contactPicker(_ picker: CNContactPickerViewController, didSelect contact:  In macOS, called when the contact picker’s popover is about to close. func contact Picker Did Close (CNContact Picker) In macOS, called when the contact picker’s popover has closed.

move the contact picker outside of the function, your losing reference to it once your out of that scope. You can make it an optional and then initialize it once the button it clicked.

CNContactPickerDelegate, contactPickerDidCancel(_:). In iOS, called when the user taps Cancel. SDKs. iOS 9.0+ In macOS, called when the contact picker's popover is about to close. A ContactPicker is a full screen control that allows the user to select a contact, multiple contacts, or an attribute of a contact. The picker can be configured to show only contacts that match specific criteria.

Did you make your view controller conform to CNContactPickerDelegate??

class MyViewController: UIViewController, CNContactPickerDelegate {

    }

Contacts - iOS 9 Swift Programming Cookbook [Book], The methods that you implement to respond to contact-picker user events. SDKs. iOS 9.0+ Called when a property of the contact has been selected by the user. func contactPickerDidCancel(CNContactPickerViewController). In iOS, called  These two delegate methods will be going to call the contact view picker and will perform the action required by us. Step 4. On the other hand, add the following code to your contact action button as shown below. This will be going to call the default contact list available in iOS Devices.

Function is never called - C++ queries, After I get the permission here, I am calling the createContact() method that we are just I did not set the year for the anniversary because an anniversary is a Issue the deleteContact(_:) function on the request and pass your mutable contact to it. func contactPickerDidCancel ( picker : CNContactPickerViewController )  The ContactPicker class enables users to select one or more contacts from any app that supports the Contact Picker contract. You can configure the ContactPicker class to accept only a single contact, or multiple contacts.

how can I use a variable from another function swift?, This query highlights functions that are non-public, non-virtual, and are never called. Dead functions are often deprecated pieces of code, and  Called when a property of the contact has been selected by the user. func contact Picker (CNContact Picker View Controller, did Select : [CNContact]) Called after contacts have been selected by the user.

Managing contacts in Swift, AddressBook and Contacts frameworks , I have a variable by the name of email in the contact picker function. nil) } func contactPickerDidCancel(_ picker: CNContactPickerViewController) But before I did that I set a global variable, a bool called initialSignUp in my case to true. error) in if error != nil{ print("did not upload image") }else{ print("uploaded") let  Resolve & Set value in PeoplePicker using JSOM function. Is there another way to call the function which activates the SharePoint behavior? but never shown

Comments
  • Does your class conforms to that delegate?