I am learning how to use DNS-SD from swift and have created a basic CLI app, however I am not getting callback results.
I can get results from cli. Something I am doing wrong here?
dns-sd -G v6 adet.local
10:06:08.423 Add 40000002 22 adet.local. FE80:0000...
dns-sd -B _adt._udp.
11:19:10.696 Add 2 22 local. _adt._udp. adet
import Foundation
import dnssd
var reference: DNSServiceRef?
func dnsServiceGetAddrInfoReply(ref: DNSServiceRef?, flags: DNSServiceFlags, interfaceIndex: UInt32, errorCode: DNSServiceErrorType, hostname: UnsafePointer<CChar>?, address: UnsafePointer<sockaddr>?, ttl: UInt32, context: UnsafeMutableRawPointer?) {
print("GetAddr'd")
print(hostname.debugDescription.utf8CString)
print(address.debugDescription.utf8CString)
}
var error = DNSServiceGetAddrInfo(&reference, 0, 0, DNSServiceProtocol(kDNSServiceProtocol_IPv6), "adet.local", dnsServiceGetAddrInfoReply, nil)
print("GetAddr: \(error)")
func dnsServiceBrowseReply(ref: DNSServiceRef?, flags: DNSServiceFlags, interfaceIndex: UInt32, errorCode: DNSServiceErrorType, serviceName: UnsafePointer<CChar>?, regType: UnsafePointer<CChar>?, replyDomain: UnsafePointer<CChar>?, context: UnsafeMutableRawPointer?) {
print("Browsed")
print(serviceName.debugDescription.utf8CString)
print(replyDomain.debugDescription.utf8CString)
}
error = DNSServiceBrowse(&reference, 0, 0, "_adt._udp", nil, dnsServiceBrowseReply, nil)
print("Browse: \(error)")
Foundation.RunLoop.main.run()
Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocalNetworkUsageDescription</key>
<string>By the Hammer of Grabthor</string>
<key>NSBonjourServices</key>
<array>
<string>_adt._udp.</string>
<string>_http._tcp.</string>
<string>_http._tcp</string>
<string>_adt._udp</string>
</array>
</dict>
</plist>