Search code examples
iosswifthomekit

Need to find the IP Address of a HomeKit device


I am wondering if anyone knows of a good way to find the ip of a HomeKit device whether through the accessory or it's services. I've scoured the HMAccessory's and HMService's properties to no avail, but maybe I'm missing something.

I though about possibly using bonjour, but I haven't been able to find much documentation (or examples) on using it to find HomeKit devices, so hopefully there's a better way.

Any suggestions? Thanks in advance


Solution

  • Figured it out, you can actually use the NSNetServiceBrowser to query a list of bonjour services on the network like so

    var dBrowser = NSNetServiceBrowser()
    dBrowser.delegate = self
    dBrowser.searchForServicesOfType("_hap._tcp", inDomain: "")
    

    and in the NSNetServiceBrowser resolved delegate method you can access the ip address in the returning service's addresses property.

    Link here for more info: http://dev.eltima.com/post/99996366184/using-bonjour-in-swift