在过去一周左右的时间里,我一直在努力解决这个问题.我已经浏览了以下资源:
I've been banging my head against this for the last week or so. I've already gone through the following resources:
我使用的是 Mac OS 10.7、Xcode 4.5、带有 iOS 6 的 iPhone 4 和带有 iOS 5.1.1 的 iPad 1.
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.
我的问题是:我正在修改一个应用程序,该应用程序当前使用 GameKit 的对等选择器在 iPad 和 iP{hone|od touch} 之间进行连接.我们想修改它以通过蓝牙使用 Bonjour,因为如果连接丢失,我们在使用 Gamekit 重新连接设备时遇到了问题.我已经使用 dns_sd.h API 取得了一些成功,并且已经获得了通过 wifi 进行广告和解析的服务,但是即使我通过了 kDNSServiceFlagsIncludeP2P,我也没有通过蓝牙获得任何成功.
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.
我认为蓝牙 Bonjour 可能需要在设备之间建立 PAN,但即使将 iPad 与 iMac 配对并浏览 DNS-SD 服务也没有给我任何帮助……而且 iPhone 也不会与 iPad 配对.
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.
在过去的 24 小时内,我刚刚在自己的应用程序中解决了这个问题.我使用了 OS X 示例应用程序 DNSSDObjects 中的核心类.我只需要更改三行代码即可添加对蓝牙的支持.这在我的 iOS 应用中效果很好.
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.
在 DNSSDBrowser.m 中,对 DNSServiceBrowse
的调用需要为第二个参数传入 kDNSServiceFlagsIncludeP2P.
In DNSSDBrowser.m, the call to DNSServiceBrowse
needs to have kDNSServiceFlagsIncludeP2P passed in for the 2nd parameter.
在 DNSSDRegister.m 中,对 DNSServiceRegister
的调用需要进行相同的更改.
In DNSSDRegister.m, the call to DNSServiceRegister
needs the same change.
在 DNSSDService.m 中,对 DNSServiceResolve
的调用也需要进行相同的更改.
In DNSSDService.m, the call to DNSServiceResolve
also needs the same change.
如果您想只使用蓝牙而不是 WiFi,则应更新相同的三行代码,以便第三个参数为 kDNSServiceInterfaceIndexP2P 而不是 kDNSServiceInterfaceIndexAny.
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.
这篇关于Bonjour 不在 BT 上做广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!