I was trying to implement FQDN to Address resolution using DNSServiceGetAddrInfo API of DNS_SD. Learning from this thread I wanted to use DNSServiceSetDispatchQueue to get results back asynchronously. Here is how I have implemented it.
var result = DNSServiceGetAddrInfo(&dnsServiceRef, kDNSServiceFlagsTimeout, 0, DNSServiceFlags(kDNSServiceProtocol_IPv4|kDNSServiceProtocol_IPv6), hostName.cString(using: .utf8), dnssd_callback, pointer)
if result != kDNSServiceErr_NoError || dnsServiceRef == nil {
delegate?.didFinishDNSResolution(.failed(.error(from: result)))
stopResolution()
} else {
result = DNSServiceSetDispatchQueue(dnsServiceRef, DispatchQueue.main)
if result != kDNSServiceErr_NoError {
delegate?.didFinishDNSResolution(.failed(.error(from: result)))
stopResolution()
}
}
However, using this implementation I do not get callbacks. If I use DNSServiceProcessResult, I am getting responses successfully. If I call DNSServiceProcessResult after DNSServiceSetDispatchQueue, then also I receive callbacks successfully. But, that is discouraged in the documentation of DNSServiceSetDispatchQueue.
> * After using DNSServiceSetDispatchQueue on a DNSServiceRef, calling DNSServiceProcessResult
* on the same DNSServiceRef will result in undefined behavior and should be avoided.
I tried DNSSDObjects and SRVResolver (with a bit change DNSServiceSetDispatchQueue) samples and they both work pretty fine. But when I use the same in my code, it does not work. So, is it possible that DNSServiceSetDispatchQueue can be used with every DNS_SD API except for DNSServiceGetAddrInfo? Or is there a missing piece?
Any help would be greatly appreciated.