vollkorntomate
vollkorntomate

Reputation: 875

Error creating the CFMessagePort needed to communicate with PPT

I try to present a CNContactPickerViewController inside a SwiftUI application using the UIViewControllerRepresentable protocol. As I already read, there seems to be a known issue for this not working, but I got it working quite ok using the workaround described here.

However, whenever the CNContactPickerViewController gets presented or dismissed resp., I get the following error in my output log:

[PPT] Error creating the CFMessagePort needed to communicate with PPT.

I tried to find explanations on this, but there seems to be no answer anywhere on the internet. Does someone know where this error comes from and what PPT is? Could this error have something to do with the CNContactPickerViewController not working properly with SwiftUI?

I noticed the error for the first time in the iOS 14 beta together with the Xcode 12 beta, and it is still present in iOS 14.2 with Xcode 12.2. I don't know if the error appears on iOS 13 as well.
I already issued a feedback report about this.

Upvotes: 43

Views: 17196

Answers (2)

Heki
Heki

Reputation: 396

This error even occurs on a virgin/clean generated project with only Hello World by Xcode 16.2 on several simulators with iOS 18.2. So I suggest to ignore it completely as it has no impact on the performance of the apps.

It points to a connection Performance Power Tools failure, but the CPU, Memory, Disk & Network performance is working correctly in the debugging session

Upvotes: 5

cs4alhaider
cs4alhaider

Reputation: 1446

I wrote a workaround using a hosting UINavigationController and here is my code:

import SwiftUI
import ContactsUI

struct ContactPickerView: UIViewControllerRepresentable {
    
    @Environment(\.presentationMode) var presentationMode
    
    func makeUIViewController(context: Context) -> UINavigationController {
        let navController = UINavigationController()
        let controller = CNContactPickerViewController()
        controller.delegate = context.coordinator
        navController.present(controller, animated: false, completion: nil)
        return navController
    }
    
    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {
        print("Updating the contacts controller!")
    }
    
    // MARK: ViewController Representable delegate methods
    func makeCoordinator() -> ContactsCoordinator {
        return ContactsCoordinator(self)
    }
    
    class ContactsCoordinator : NSObject, UINavigationControllerDelegate, CNContactPickerDelegate {
        let parent: ContactPickerView
        public init(_ parent: ContactPickerView) {
            self.parent = parent
        }
        
        func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
            print("Contact picked cancelled!")
            parent.presentationMode.wrappedValue.dismiss()
        }
        
        func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
            print("Selected a contact")
            parent.presentationMode.wrappedValue.dismiss()
        }
    }
}

And I use it like:

Button("Select a contact") {
       openSelectContact.toggle()
}
 .sheet(isPresented: $openSelectContact, onDismiss: nil) {
       ContactPickerView()
     }

Upvotes: 4

Related Questions