問題描述
在過去一周左右的時間里,我一直在努力解決這個問題.我已經瀏覽了以下資源:
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 Over Bluetooth 的工作原理 (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 上做廣告的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!