Search code examples
iosswiftcncontactcncontactviewcontroller

Present EditView of Contacts in ContactsUI


I have a TableView that present a contact. When I click the cell i would like to do straight to Editable view, instead of going to the CNContactViewController and press "edit Button". Now i have the following :

firstview

secondview

I would like to skip the second step. Is that possible?

the code I'm using is the same from apple's:

let contacts = try contactStore.unifiedContactWithIdentifier
        (contactIdentifier!, keysToFetch: toFetch)
    let controller = CNContactViewController(forContact: contacts)
        controller.contactStore = contactStore
        controller.delegate = self
        controller.editing = true

        navigationController?
            .pushViewController(controller, animated: true)
        print(controller.editButtonItem())

    } catch {
        print(error)
    }

EDIT: More or less, to illustrate, what Im trying to do, is the same as WhatsApp has in their App!, thanks!!


Solution

  • Have you tried this approach ?

    let toFetch = [CNContactViewController.descriptorForRequiredKeys()]
    
    let contacts = try contactStore.unifiedContactWithIdentifier
            (contactIdentifier!, keysToFetch: toFetch)
    
    let contactsViewController = CNContactViewController(forNewContact: contacts)
    contactsViewController.delegate = self
    contactsViewController.title = "Edit contact"
    contactsViewController.contactStore = contactStore
    
    self.navigationController?.pushViewController(contactsViewController, animated: true)