I am trying send data multicast address via using NWConnectionGroup, I tried below code at iOS 15 version it works, it sends data and I received sended data, but When I try at iOS 17 version it connects successfully url and port, but it doesn't sending data, Why I can't send data from iOS 17 version, Can I need get specific permission? meanwhile I tested in simulator at iOS 17.2 version it sends data but real device can't send data.
func init() {
var group: NWConnectionGroup!
connect(withHost: "235.10.10.100", port: 3333)
}
func connect(withHost: NWEndpoint.Host, port: NWEndpoint.Port) {
let multicast = try! NWMulticastGroup(for: [.hostPort(host: withHost, port: port)])
group = NWConnectionGroup(with: multicast, using: .udp)
group.setReceiveHandler(maximumMessageSize: 128) { message, data, b in
print("Received message:")
}
group.stateUpdateHandler = { (newState) in
print("Group entered state \(String(describing: newState))")
}
group.start(queue: .global())
}
func sendData() {
let groupSendContent = Data("helloAll".utf8)
self.group.send(content: groupSendContent) { error in (error)
print("Send complete with error \(String(describing: error))")
}
}
Use of NWMulticastGroup requires the com.apple.developer.networking.multicast entitlement. There is a link for requesting it in the documentation.
I do not recommend just modifying the entitlement file by hand. It's tricky to do correctly. I recommend adding it in Signing & Capabilities. Add it through the "+ Capability" button:

Note that you will need to have this entitlement on your provisioning profile. You need to request it from Apple using the link described above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With