Right, because if your UDP listener never receives any messages then you’ll never start the outgoing TCP connection. I was able to receive UDP packets and then set up a TCP connection without triggering the network permissions, so long as I wasn't using Bonjour. This was on iOS 14 with no entitlements listed in the info.plist, and an empty Bonjour array.
I was under the impression that you’re using UDP broadcasts? If so, NWListener and NWConnection are not appropriate. I am. My current implementation (updated from the OP) is to receive the UDP broadcasts via an NWListener (which uses Bonjour) and then set up an NWConnection on the port to read the messages. This is functional on iOS 14. Emailing with Network Entitlement Requests suggested I should accomplish the UDP reception via Bonjour, so I implemented the below. Should I be using something different?
	var udpListener: NWListener?
var udpConnection: NWConnection?
var backgroundQueueUdpListener = DispatchQueue.main
func findUDP() {
let params = NWParameters.udp
udpListener = try? NWListener(using: params, on: 15000)
udpListener?.service = NWListener.Service.init(type: "_appname._udp")
self.udpListener?.stateUpdateHandler = { update in
print("update")
print(update)
switch update {
case .failed:
print("failed")
default:
print("default update")
}
}
self.udpListener?.newConnectionHandler = { connection in
print("connection")
print(connection)
self.createConnection(connection: connection)
self.udpListener?.cancel()
}
udpListener?.start(queue: self.backgroundQueueUdpListener)
}
func createConnection(connection: NWConnection) {
self.udpConnection = connection
self.udpConnection?.stateUpdateHandler = { (newState) in
switch (newState) {
case .ready:
print("ready")
self.send()
self.receive()
case .setup:
print("setup")
case .cancelled:
print("cancelled")
case .preparing:
print("Preparing")
default:
print("waiting or failed")
}
}
self.udpConnection?.start(queue: .global())
}
func endConnection() {
self.udpConnection?.cancel()
}
Topic:
Code Signing
SubTopic:
Entitlements
Tags: