Dear Girls, Guys and Engineers.
I'm currently building a Home Network Scanner App for People which want to know which Bonjour Devices are in her/his Home Network environment. From an older Question I got the answer, that I need an Entitlement to do this.
I started to work on the App and requested the Multicast Entitlement from Apple. They gave me the Entitlement for my App and now I'm trying to discover all devices in my Home Network but I got stuck and need Help.
I only test direct on device, like the recommendation. I also verified that my app is build with the multicast entitlement there where no problems. My problem is now, that is still not possible to discover all Bonjour services in my Home Network with the Help of the NWBrowser.
Can you please help me to make it work ?
I tried to scan for the generic service type:
let browser = NWBrowser(for: .bonjour(type: "_services._dns-sd._udp.", domain: nil), using: .init())
but this is still not working even tough I have the entitlement and the app was verified that the entitlement is correctly enabled
if I scan for this service type, I got the following error:
[browser] nw_browser_fail_on_dns_error_locked [B1] Invalid meta query type specified. nw_browser_start_dns_browser_locked failed: BadParam(-65540)
So what's the correct way now to find all devices in the home network ?
Thank you and best regards Vinz
I’m gonna focus on iOS for the moment, because I’m seeing some results on macOS that I can’t readily explain.
On iOS you need the Multicast Network capability and the NSLocalNetworkUsageDescription
property in your Info.plist
.
Running the code below I see output like this:
browser will start
browser did find, service: <NSNetService 0x15c18ac00> . _tcp.local. _afpovertcp -1
browser did find, service: <NSNetService 0x15c18ac00> . _tcp.local. _ipp -1
browser did find, service: <NSNetService 0x15c18ac00> . _tcp.local. _ipps -1
browser did find, service: <NSNetService 0x15c18ac00> . _tcp.local. _ipp-tls -1
browser did find, service: <NSNetService 0x15c18ac00> . _tcp.local. _http -1
…
This seems to be working as expected, that is, it’s reporting all the service types discovered on the local network.
You wrote:
however calls to resolve for each service, result in didNotResolve.
Right, because you can’t resolve a service type. Rather, you’re expected to get the type from each result (via the name
property) and start new browser for services of that type. That’ll results in services that you can then resolve. Consider:
(lldb) po service.name
_afpovertcp
(lldb) po service.type
_tcp.local.
(lldb) po service.domain
.
Once you get this working on iOS, lemme know and we can talk about the macOS situation.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
@Observable
final class AppModel: NSObject, NetServiceBrowserDelegate {
var browserQ: NetServiceBrowser? = nil
func startStop() {
if let browser = self.browserQ {
self.browserQ = nil
self.stop(browser: browser)
} else {
self.browserQ = self.start()
}
}
private func start() -> NetServiceBrowser {
print("browser will start")
let browser = NetServiceBrowser()
browser.delegate = self
browser.searchForServices(ofType: "_services._dns-sd._udp.", inDomain: "local.")
return browser
}
private func stop(browser: NetServiceBrowser) {
print("browser will stop")
browser.delegate = nil
browser.stop()
}
func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) {
print("browser did find, service: \(service)")
}
func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String : NSNumber]) {
print("did not search, error: \(errorDict)")
}
}