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
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