Hi,
Objective:
iOS 14, iPhone needs to connect to device on local network without knowing its hostname; only port is known.
Do I understand it correctly that the only way to do it is to request com.apple.developer.networking.multicast entitlement and execute:
guard let multicast = try? NWMulticastGroup(for:
[ .hostPort(host: "224.0.0.251", port: 5353) ])
else { fatalError(...) }
let group = NWConnectionGroup(from: multicast, using: .udp)
group.setReceiveHandler(maximumMessageSize: 16384, rejectOversizedMessages: true) { (message, content, isComplete) in
print("Received message from \(String(describing: message.remoteEndpoint))")
}
Then from message.remoteEndpoint I can infer hostname (with matching port, of course) to which I need initiate NWConnection?
Thanks
Code source - https://developer.apple.com/news/?id=0oi77447
2
0
957