問(wèn)題描述
在過(guò)去一周左右的時(shí)間里,我一直在努力解決這個(gè)問(wèn)題.我已經(jīng)瀏覽了以下資源:
I've been banging my head against this for the last week or so. I've already gone through the following resources:
- StackOverflow:在沒(méi)有 Gamekit 的情況下通過(guò)藍(lán)牙享受 Bonjour ?(3844189)
- StackOverflow:Bonjour Over Bluetooth 的工作原理 (3350094)
- StackOverflow:在其他平臺(tái)上使用 iOS GameKit 的Bluetooth Bonjour" (8070998)
- 技術(shù)問(wèn)答 QA1753 -- Apple 開(kāi)發(fā)者
- WiTap 示例應(yīng)用程序
- SRVResolver 示例應(yīng)用程序
- DNSSDObjects 示例應(yīng)用程序
我使用的是 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.
我的問(wèn)題是:我正在修改一個(gè)應(yīng)用程序,該應(yīng)用程序當(dāng)前使用 GameKit 的對(duì)等選擇器在 iPad 和 iP{hone|od touch} 之間進(jìn)行連接.我們想修改它以通過(guò)藍(lán)牙使用 Bonjour,因?yàn)槿绻B接丟失,我們?cè)谑褂?Gamekit 重新連接設(shè)備時(shí)遇到了問(wèn)題.我已經(jīng)使用 dns_sd.h API 取得了一些成功,并且已經(jīng)獲得了通過(guò) wifi 進(jìn)行廣告和解析的服務(wù),但是即使我通過(guò)了 kDNSServiceFlagsIncludeP2P,我也沒(méi)有通過(guò)藍(lán)牙獲得任何成功.
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.
我認(rèn)為藍(lán)牙 Bonjour 可能需要在設(shè)備之間建立 PAN,但即使將 iPad 與 iMac 配對(duì)并瀏覽 DNS-SD 服務(wù)也沒(méi)有給我任何幫助……而且 iPhone 也不會(huì)與 iPad 配對(duì).
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.
推薦答案
在過(guò)去的 24 小時(shí)內(nèi),我剛剛在自己的應(yīng)用程序中解決了這個(gè)問(wèn)題.我使用了 OS X 示例應(yīng)用程序 DNSSDObjects 中的核心類.我只需要更改三行代碼即可添加對(duì)藍(lán)牙的支持.這在我的 iOS 應(yīng)用中效果很好.
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 中,對(duì) DNSServiceBrowse
的調(diào)用需要為第二個(gè)參數(shù)傳入 kDNSServiceFlagsIncludeP2P.
In DNSSDBrowser.m, the call to DNSServiceBrowse
needs to have kDNSServiceFlagsIncludeP2P passed in for the 2nd parameter.
在 DNSSDRegister.m 中,對(duì) DNSServiceRegister
的調(diào)用需要進(jìn)行相同的更改.
In DNSSDRegister.m, the call to DNSServiceRegister
needs the same change.
在 DNSSDService.m 中,對(duì) DNSServiceResolve
的調(diào)用也需要進(jìn)行相同的更改.
In DNSSDService.m, the call to DNSServiceResolve
also needs the same change.
如果您想只使用藍(lán)牙而不是 WiFi,則應(yīng)更新相同的三行代碼,以便第三個(gè)參數(shù)為 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.
這篇關(guān)于Bonjour 不在 BT 上做廣告的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!