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.ready:
print("starting")
case .failed(let error):
print("error: \(error)")
default:
print(newState)
}
}
listener.start(queue: .main)
However, the status
is failed with error message:
POSIXErrorCode(rawValue: 22): Invalid argument