iOS - Multicast networking failed

here my code to using multicast : guard let multicast = try? NWMulticastGroup(for:       [ .hostPort(host: "224.0.0.251", port: 5353) ])       else { return }

 self.group = NWConnectionGroup(with: multicast, using: .udp)       group.setReceiveHandler(maximumMessageSize: 16384, rejectOversizedMessages: true) { (message, content, isComplete) in print("Received message from (String(describing: message.remoteEndpoint))")

let sendContent = Data("ack".utf8) message.reply(content: sendContent) }       group.stateUpdateHandler = { (newState) in print("Group entered state (String(describing: newState))") } group.start(queue: .main)

i have try every library for socket and every time get error on real ios device ios 14 and 15

when start happen stateDidUpdate called with field : 2021-11-01 11:07:21.106160+0200 SamRiskSDKPOC[1528:39332] [connection_group] nw_connection_group_handle_listener_state_change [G1] listener failed with error Group entered state waiting(POSIXErrorCode: Network is down) Group entered state failed(POSIXErrorCode: Address already in use)

iv request for using multicast network from apple , get approved add the capability:

iv created .entitlement file and add to app setting

after i create developer provision profile and download it and run those:

➜ ~ codesign -d --entitlements :- /Users/menny-a/Library/Developer/Xcode/DerivedData/SamRiskSDKPOC-gccczhfgcyqowifmuucaawrwfibu/Build/Products/Debug-iphoneos/SamRiskSDKPOC.app | grep -A 1 "com.apple.developer.networking.multicast" Executable=/Users/menny-a/Library/Developer/Xcode/DerivedData/SamRiskSDKPOC-gccczhfgcyqowifmuucaawrwfibu/Build/Products/Debug-iphoneos/SamRiskSDKPOC.app/SamRiskSDKPOC com.apple.developer.networking.multicast ➜ ~ security cms -D -i /Users/menny-a/Library/Developer/Xcode/DerivedData/SamRiskSDKPOC-gccczhfgcyqowifmuucaawrwfibu/Build/Products/Debug-iphoneos/SamRiskSDKPOC.app/embedded.mobileprovision | grep -A 1 "com.apple.developer.networking.multicast" com.apple.developer.networking.multicast after i done this my plist change :

on ios simulatore work perfect on read ios device not please help

You will want to make sure that you test this on a physical device connected to Wi-Fi to know that the Multicast feature is actually working. It looks like you are mentioning that you have included the Multicast Entitlement in your app's entitlement file, but I just wanted to confirm that this is added to your app's entitlement file:

<key>com.apple.developer.networking.multicast</key>
<true/>

Also, Quinn wrote a great post on Using the Multicast Entitlement, once you have it.

Matt Eaton
DTS Engineering, CoreOS
meaton3@a

Hi Matt as you can see i done everything

i just want to mention

that NWMulticastGroup(for:[.hostPort(host: "239.255.255.250", port: 1900)] (SSDP) WORk and this issue is on : NWMulticastGroup(for:[.hostPort(host: "224.0.0.251", port: 5353)] (MDNS)

also i want to mention that on simulator i get to prompt to allow communication

and it working

but on physical device , it not work the prompt not shows

please help me to solve this :)

Same issue trying to use NSMulticastGroup on iPadOS in a SwiftPlayGrounds4 app...with 224.0.0.251:5353

Local Network capabilities added and Bonjour serive types listed...

When testing Multicast functionality in iOS, please make sure that you are always testing it on an actual device for the best possible test results. Testing this on a simulator or in Playground will use the networking stack of the actual macOS device that the simulator or playground is running in.

For NWMulticastGroup, there was a previous bug in the iOS 14.7 timeframe (r. 70172599) that did see some issues with unicasting responses back to senders with the Swift API. This should be fixed now in iOS 15. If you further run into issues, the BSD APIs still does work for sending multicast messages back and forth in a pinch.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
iOS - Multicast networking failed
 
 
Q