寻找触手可及的通用蓝牙设备
我们正在使用 iOS 私有框架 BluetoothManager 进行一个简单的实验——寻找可发现的通用(非 iOS)BT 设备。现在,只有以下行返回设备:
for(BluetoothDevice* device in [[BluetoothManager共享实例]pairedDevices])
不幸的是,它只返回已经配对的设备,这并不是我们想要的。使用 connectingDevices
而不是 pairedDevices
根本不会返回任何设备。那么,我们有什么选择能够检测到触手可及的任何蓝牙设备呢?我认为我不能使用 GameKit,因为我想发现非 iOS 设备。
欢迎任何建议。
We are using the iOS private framework BluetoothManager for a simple experiment -- to find discoverable generic (non-iOS) BT devices within reach. Now, only the following line returns devices:
for(BluetoothDevice* device in [[BluetoothManager sharedInstance] pairedDevices])
Unfortunately it only returns devices already paired, which isn't quite what we want. Using connectingDevices
instead of pairedDevices
does not return any device at all. So, what options do we have to be able to detect any Bluetooth device within reach? I don't think I can use GameKit because I want to discover non-iOS devices.
Any suggestions are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这几天我一直在摆弄私有框架,获取附近设备的列表非常简单。
首先,您必须使用以下方式启用设备扫描:
如果范围内有设备,它将开始向通知中心发布 BluetoothDeviceDiscoveredNotification 通知。订阅这些,并且传递给回调的 NSNotification 中的对象将是 BluetoothDevice* 类型。
我确信蓝牙管理器将所有发现的设备存储在某个地方,但我只是将所有内容都放入我自己的 NSMutableArray 中。
不幸的是,我仍然没有弄清楚如何使用私有 API 与设备实际配对。
I've been messing with the private framework for a few days, and getting a list of nearby devices is pretty straightforward.
First, you have to enable device scanning using:
If there are devices within range it will start posting BluetoothDeviceDiscoveredNotification notifications to the notification center. Subscribe to these and the object in the NSNotification delivered to the callback will be of type BluetoothDevice*.
I'm sure the BluetoothManager stores any discovered devices somewhere, but I just threw everything into my own NSMutableArray.
Unfortunately I still haven't figured out how to actually pair with a device using the private API.
您需要使用BluetoothManager 打开蓝牙,然后启用远程设备的蓝牙扫描。
注册通知回调后,您将获得发现的设备。通知对象实际上是一个指向BluetoothDevice 对象的指针。
获取BluetoothDevice对象指针,从那里您可以获得名称、地址或连接到远程设备。
这里没有RSSI,您可以通过查看BluetoothDevice.h文件来查看完整的方法列表。
我在这里编写了一个与 iOS 5.1 兼容的完整示例: http://www.pocketmagic.net/? p=2827
祝你好运!
You need to use BluetoothManager to turn Bluetooth on, and then to enable bluetooth scanning of remote devices.
Having registered a notification callback, you will get the discovered devices. The notification object is actually a pointer to a BluetoothDevice object.
Get the BluetoothDevice object pointer, and from there you can get the name, address or connect to the remote device.
There is no RSSI here, you can see the complete list of methods by looking at the BluetoothDevice.h file.
I wrote a complete sample, compatible with iOS 5.1, here: http://www.pocketmagic.net/?p=2827
Good luck!
GKSession 类是 GameKit 框架的一部分,正是您所需要的,因为它提供了使用蓝牙发现和连接到附近 iOS 设备的能力。
The GKSession class which is part of the GameKit framework is what you are looking for as it provides the ability to discover and connect to nearby iOS devices using Bluetooth.