I want to be able to enumerate the names of devices on a local network from a device running iPhone OS 3.x (iPhone/iPad). I have tried using NSNetServiceBrowser to find all services like so:
[serviceBrowser searchForServicesOfType:@"_services._dns-sd._udp." inDomain:@"local."];
this returns results but when I try and resolve the addresses I get the following errors back
NSNetServicesErrorCode = -72004;
NSNetServicesErrorDomain = 10;
I have looked up the error and it appears there is a bad argument?
[kCFNetServiceErrorBadArgument
A required argument was not provided or was not valid.]
if I do a service specific search like
[serviceBrowser searchForServicesOfType:@"_ipp._tcp." inDomain:@""];
resolutions works fine.
So, am I on the right track with NSNetServiceBrowser or is there some other method that will allow me to enumerate the names of devices connected to my network?
If you open up the Find My app and navigate to the Items tab, you can see all of your Find My-compatible accessories on a map. You'll see current location if the accessory is able to communicate with your iPhone, iPad, or Mac over Bluetooth, or the last known location if it is too far away.
“Apps that access your local network can collect information about nearby devices in order to determine which networks you join and when. This information could be used to create a profile of you.
This is the correct approach. Potentially, the reason you have a NSNetServicesBadArgumentError
is because your serviceType string @"_services._dns-sd._udp."
is invalid try @"_services._dns-sd._udp"
instead i.e. without the trailing period.
Apple's documentation is confusing on this point. In the NSNetServiceBrowser Class Reference it states that:
The serviceType argument must contain both the service type and transport layer information. To ensure that the mDNS responder searches for services, rather than hosts, make sure to prefix both the service name and transport layer name with an underscore character (“_”). For example, to search for an HTTP service on TCP, you would use the type string “_http._tcp.“. Note that the period character at the end is required.
However, in the NSNetServices and CFNetServices Programming Guide, the example for Initializing the Browser and Starting a Search clearly doesn't use a period at the end:
serviceBrowser = [[NSNetServiceBrowser alloc] init];
[serviceBrowser setDelegate:delegateObject];
[serviceBrowser searchForServicesOfType:@"_music._tcp" inDomain:@""];
Try it without & see if ou have any luck.
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