问题描述
在过去的一周左右的时间里,我一直在反对这个.我已经浏览了以下资源:
I've been banging my head against this for the last week or so. I've already gone through the following resources:
- StackOverflow:在没有 Gamekit 的情况下通过蓝牙实现 Bonjour?(3844189)
- StackOverflow:Bonjour 如何通过蓝牙工作 (3350094)
- StackOverflow:在其他平台上使用 iOS GameKit 的Bluetooth Bonjour" (8070998)
- 技术问答 QA1753 -- Apple 开发人员
- WiTap 示例应用程序
- SRVResolver 示例应用程序
- DNSSDObjects 示例应用程序
我使用的是 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 做广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!