简体   繁体   English

iOS蓝牙设备列表

[英]iOS Bluetooth Device List

I would like to use Bluetooth as a drive for an app. 我想将蓝牙用作应用程序的驱动器。

I need to be able to let the user pick a chosen device from 'Settings>Bluetooth>My Devices', so I am looking for how I can get this list in my code. 我需要让用户从“设置”>“蓝牙”>“我的设备”中选择一个选定的设备,因此我正在寻找如何在我的代码中获取此列表的方法。

Once I have the details of the selected device, I would like to be able to register for notifications whenever this device is connected (or whenever any bluetooth device connects and I can parse the data to check for a match). 获得选定设备的详细信息后,我希望能够在连接该设备时(或在连接任何蓝牙设备并且可以解析数据以检查是否匹配时)注册通知。

The devices I am looking for are Car Kit's. 我要寻找的设备是车载套件。 Looking at the console log when I try this in my own car, I notice that I see mediaserverd[19] : BTAudioXpcConnection.cpp within the console log. 在自己的车上尝试查看控制台日志时,我注意到在控制台日志中看到mediaserverd [19]:BTAudioXpcConnection.cpp。 I am assuming therefore that the LEAudio perhaps points to the need to use the Low Energy side? 因此,我假设LEAudio可能指向使用低能耗方面的需求?

In short, 1) I need to list the paired devices, and 2) I need to get a notification when a given device connects. 简而言之,1)我需要列出配对的设备,2)当给定设备连接时,我需要获得通知。

Can anyone advise if this is possible, and if so, point me at some useful documentation, as the docs I have read so far do not seem to give me what I need. 任何人都可以建议这是否可行,如果可以的话,请向我指出一些有用的文档,因为到目前为止我阅读的文档似乎并不能满足我的需求。

Thanks. 谢谢。

To get a list of bluetooth devices in range inside your app you can use the CoreBluetooth framework. 要获取应用程序内部范围内的蓝牙设备列表,您可以使用CoreBluetooth框架。

From here you can connect to the device and get its details. 从这里您可以连接到设备并获取其详细信息。

If you design your app to show a list of all devices then allow the user to connect to one, saving this devices details will allow you to have a "My Devices" section in your app. 如果您设计的应用程序显示所有设备的列表,然后允许用户连接到一个设备,则保存此设备的详细信息将使您在应用程序中拥有“我的设备”部分。 Whenever they are in range simply connect to them. 只要它们在范围内,只需连接它们即可。

I have made a wrapper round the CoreBluetooth framework to make it easier for people to use. 我为CoreBluetooth框架做了一个包装,以使人们更容易使用。

https://github.com/steprescott/SCPCoreBluetoothManager https://github.com/steprescott/SCPCoreBluetoothManager

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM