Bonjour not advertising over BT

扶醉桌前 提交于 2019-12-18 13:36:54

问题


I've been banging my head against this for the last week or so. I've already gone through the following resources:

  • StackOverflow: Bonjour over bluetooth WITHOUT Gamekit ? (3844189)
  • StackOverflow: How does Bonjour Over Bluetooth Work (3350094)
  • StackOverflow: Using iOS GameKit's “Bluetooth Bonjour” with other platforms (8070998)
  • Technical Q&A QA1753 -- Apple Developer
  • WiTap sample application
  • SRVResolver sample application
  • DNSSDObjects sample application

I'm using Mac OS 10.7, Xcode 4.5, an iPhone 4 with iOS 6, and an iPad 1 with iOS 5.1.1.

My problem is this: I am modifying an application that currently uses GameKit's peer picker to connect between an iPad and a iP{hone|od touch}. We want to modify this to use Bonjour over Bluetooth instead because we've had issues with reconnecting the devices using Gamekit if the connection is lost. I've used dns_sd.h API to some success and have gotten the service to advertise and resolve over wifi, but even though I am passing kDNSServiceFlagsIncludeP2P I am not getting any success over bluetooth.

I thought possibly Bluetooth Bonjour need a PAN established between devices already, but even pairing the iPad to the iMac and browsing for DNS-SD services gives me nothing...and the iPhone won't pair to the iPad anyway.


回答1:


I just finished solving this in my own app in the last 24 hours. I used the core classes from the OS X sample app DNSSDObjects. I only had to change three lines of code to add support for bluetooth. This works great in my iOS app.

In DNSSDBrowser.m, the call to DNSServiceBrowse needs to have kDNSServiceFlagsIncludeP2P passed in for the 2nd parameter.

In DNSSDRegister.m, the call to DNSServiceRegister needs the same change.

In DNSSDService.m, the call to DNSServiceResolve also needs the same change.

If you want to limit yourself to just bluetooth, and not WiFi, then the same three lines of code should be updated so the 3rd parameter is kDNSServiceInterfaceIndexP2P instead of kDNSServiceInterfaceIndexAny.




回答2:


Indeed, it looks like the kDNSServiceInterfaceIndexP2P flag won't work on OSX.

If you run the code on IOS, you'll notice that Bonjour will publish two IP Adresses: one for your local WiFi network, and an 169.xx.xx.xx adress for Bluetooth.

The same code on OSX never publishes the 169.xx.xx.xx adress, so it's only found over WiFi.



来源:https://stackoverflow.com/questions/12982389/bonjour-not-advertising-over-bt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!