DNSServiceQueryRecord works on iOS 12, not ios 13

Any idea why this code works great on iOS 12, and not on iOS 13?


DNSServiceRef dnsServiceReference;

DNSServiceErrorType dnsServiceQueryError = DNSServiceQueryRecord(&dnsServiceReference, kDNSServiceFlagsForceMulticast | kDNSServiceFlagsTimeout, kDNSServiceInterfaceIndexAny, [arpAddress UTF8String], kDNSServiceType_PTR, kDNSServiceClass_IN, QueryRecordCallback, (__bridge void *)(self));

if (dnsServiceQueryError == kDNSServiceErr_NoError) {

DNSServiceErrorType callbackError = DNSServiceSetDispatchQueue(dnsServiceReference, dispatch_get_main_queue());

NSAssert(callbackError == kDNSServiceErr_NoError, @"there was an error!");

}

There’s a lot of info to go on here. Let’s start with something straightforward: How does this fail? Do you get an error? Or is it simply that the callback is never called?

Share and Enjoy

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

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

Since adding the flag kDNSServiceFlagsTimeout, the callback is called with an error indicating that it timed out. Before adding that flag, the callback would never be called. (on my iPad Pro running iOS 13.3)


Of course when executing it on my iPad Pro running 12.3.1 the callback is called either way.


Furthermore, and more importantly, when the callback is called on the iPad Pro running 12.3.1 the machine name of the arp address that was provided when I called DNSServiceQueryRecord, is provided via the callback through the parameter called rdata in the callback example below:


static void QueryRecordCallback (

DNSServiceRef dnsServiceReference,

DNSServiceFlags flags,

uint32_t interfaceIndex,

DNSServiceErrorType errorCode,

const char * fullname,

uint16_t rrtype,

uint16_t rrclass,

uint16_t rdlen,

const void * rdata,

uint32_t ttl,

void * context) {


DNSServiceRefDeallocate(dnsServiceReference);


char result[1024] = {0};

dn_expand(rdata, rdata + rdlen, rdata, result, 1024);

if (strlen(result) > 0) {

NSString *machineName = [[NSString stringWithUTF8String: result] stringByDeletingPathExtension];

}

}

And to add insult to injury, it works fine on the simulator, iPad Pro, iOS 13.3

I guess I can assume this is a bug in iOS 13, since I have not received a response.

Sorry I didn’t respond sooner. To give you a definitive answer here I’d need to dig into this in detail, and that’s more than I can do here in DevForums. My recommendation is that you open a DTS tech support incident and I, or one of my colleagues, will take a proper look.

Share and Enjoy

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

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

Ok, I can do that but meanwhile I just need my app to work. Do you know a reliable way to retrieve the dns name of a device on a local network, given its ip address?

There’s no 100% reliable way to do this. The technique you’re currently using only works if the device has an mDNS responder with the appropriate

PTR
records registered. Not all devices have that.

Share and Enjoy

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

let myEmail = "eskimo" + "1" + "@apple.com"
DNSServiceQueryRecord works on iOS 12, not ios 13
 
 
Q