2

I'm working with SwiftUI, I'm using a NavigationView, then a NavigationLink which takes to a UIViewControllerRepresentable of a CNContactViewController.

UIViewControllerRepresentable:

import SwiftUI
import ContactsUI

struct ContactView: UIViewControllerRepresentable {
    let contact: CNContact
    
    class Coordinator: NSObject, CNContactViewControllerDelegate {
        
        let contacts: Contacts
        
        init(contacts: Contacts) {
            self.contacts = contacts
        }
        
        func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
        }
    }
    
    init (_ contact: CNContact) {
        self.contact = contact
    }

    func makeUIViewController(context: Context) -> CNContactViewController {
        let controller = CNContactViewController(for: contact)
        controller.allowsEditing = true
        controller.contactStore = contacts.contactStore
        controller.message = ""
        controller.delegate = context.coordinator
        
        return controller
    }
    
    func makeCoordinator() -> Coordinator {
        return Coordinator(contacts: contacts)
    }

    
    func updateUIViewController(_ uiViewController: CNContactViewController, context: Context) {
        
    }
} 

Navigation Link:

NavigationView {
   List {
      let contact = ... // get an existing contact from the contact store

      NavigationLink(destination: ContactView(contact)) {
         Text("Show Contact")
      }
   }
}

Button disappears and reappears:

Button disappears and reappears

Here is a demo project on GitHub if you want to run it easily

  • This requires debugging, so would you prepare minimal reproducible example, because provided code snapshots are not testable. – Asperi Jan 08 '21 at 15:30
  • Same problem here. I get a warning that the CNContactViewController is added to a controller that is NOT a navigation controller and that the parent navigation item is automatically updated. Did someone has found any solution? – J.E.K Jun 18 '21 at 14:05
  • What I did was use UIKit instead of SwiftUI – Matteo judomat Meluzzi Jun 20 '21 at 10:45
  • Any news how to solve this in SwiftUI? – kjanker Nov 14 '22 at 23:04

0 Answers0