0

I have a task to show the contact editing screen at once during his appearance (such as WhatsApp), I show him the following way.

   @objc private func presentContactEditController() {
        guard var contact = contactModel.contact else { return }
        if !contact.areKeysAvailable([CNContactViewController.descriptorForRequiredKeys()]) {
            do {
                let contactStore = CNContactStore()
                contact = try contactStore.unifiedContact(withIdentifier: contact.identifier, keysToFetch: [CNContactViewController.descriptorForRequiredKeys()])
            } catch {
                debugPrint("presentContactEditController error", error.localizedDescription)
            }
        }
        let cnContactViewController = CNContactViewController(for: contact)
        cnContactViewController.delegate = self
        cnContactViewController.setEditing(true, animated: false)

        let contactNaviController = UINavigationController(rootViewController: cnContactViewController)
        present(contactNaviController, animated: true, completion: nil)
    }

But there is a screen with information about this contact. So I tried to do it through the heir of CNContactViewController, different methods ViewController life cycle, but it works only in viewDidAppear method, but it will be visible to the user. How can I solve this problem? Thank you.

Alexander Khitev
  • 6,417
  • 13
  • 59
  • 115

2 Answers2

1

just change let cnContactViewController = CNContactViewController(for: contact)

to

let cvc = CNContactViewController(forNewContact: contact)

it will work for you

0

I came to the conclusion that that WhatsApp create a custom screen for this purpose. Just I saw the same screen in Telegram only with a modified design.

Alexander Khitev
  • 6,417
  • 13
  • 59
  • 115