How to create and advertise a Bonjour service with Network.framework?

I'm trying to create and advertise a Bonjour service via Network.framework.

In Xcode, target, Info tab, I've added the entry to plist:

And then written the following code:

        guard let listener = try? NWListener(service: .init(name: "My Printer Service", type: "_printer._tcp"),using: .tcp) else {
            return nil
        self.listener = listener
        listener.stateUpdateHandler = { newState in
            switch newState {
            case .failed(let error):
                print("error: \(error)")
        listener.start(queue: .main)

However, the status is failed with error message:
POSIXErrorCode(rawValue: 22): Invalid argument

I see you asked the same question over on DevForums, and I’ll respond there in a few minutes.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple