NWBrowser find all mDNS Services ?

Hello,


i want to find all open mDNS services with the new NWBrowser. With the NetServiceBrowser i got all Services by searching for this type: "_services._dns-sd._udp." but with the NWBrowser i dont get anything. if i search for a specific type like http or companion link i find some devices. How can i get all services with the NWBrowser ? Or is this not possible due to new data collection guidelines ? I tried it in a Playground


import Network

let parameter = NWParameters()
parameter.includePeerToPeer = true
let browser = NWBrowser(for: .bonjour(type: "_services._dns-sd._udp.", domain: nil), using: parameter)
browser.stateUpdateHandler = { state in
    switch state {
    case .ready:
        print("ready")
    case .failed(let error):
        print("error:", error.localizedDescription)
    default:
        break
    }
}
browser.browseResultsChangedHandler = { result, changed in
    result.forEach { device in
        print(device.endpoint)
        print(device.metadata)
    }
}
browser.start(queue: .main)
PlaygroundPage.current.needsIndefiniteExecution = true
Answered by Engineer in 615064022
Detecting all devices on a home network is a privacy-sensitive task, and not appropriate for most general-purpose uses of NWBrowser.

In iOS 14, in order to discover all Bonjour services, you will need to request an entitlement. It will make sense for apps that are utilities to help scan a network to have this entitlement, but most apps don't need that. Using one or a few Bonjour services just needs an Info.plist key.

You can find more info on how to get the entitlement here: How to use multicast networking in your app

I’m not sure what’s going on here but I’m quite surprised that this doesn’t work. The goal of

NWBrowser
is to supplant older APIs, like
NetServiceBrowser
, while avoiding the really low-level DNS-SD API, and this limitation runs counter to that goal. So, I recommend that you file a bug about this.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

thanks for your answer. i reported this as a bug, the bug number is the following: #6175545

i reported this as a bug

Thanks. I’m not sure if you’ve been notified of this via the feedback system yet, but your bug is coming back as ‘behaves correctly’. It seems that browsing for service types is not an expected feature of

NWBrowser
. Colour me surprised, eh?

Can I ask more about what your goals are here? Browsing for service types is a relatively unusual task, so I’m curious what you’re doing with the results?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
(r. 51886685)
Hi,

my reply comes late, I know ^_^

but today is started to try it again, sad that it's still not working.

The Idea behind that is, that I worked on a simple app which helps the user to detect all devices which are in his home network environment. One way to detect some devices is to make this generic mDNS lookup to get all service types and with the help of the interface name you can do a estimation which device it could be.

or is there any better solution which apple provides to detect devices in a home network ? or is this something that is not allowed due to data privacy restrictions ?

best regards,
Vinz
Accepted Answer
Detecting all devices on a home network is a privacy-sensitive task, and not appropriate for most general-purpose uses of NWBrowser.

In iOS 14, in order to discover all Bonjour services, you will need to request an entitlement. It will make sense for apps that are utilities to help scan a network to have this entitlement, but most apps don't need that. Using one or a few Bonjour services just needs an Info.plist key.

You can find more info on how to get the entitlement here: How to use multicast networking in your app
Ah great, thank you for your reply :)

Best regards,
Vinz
NWBrowser find all mDNS Services ?
 
 
Q