CoreBluetooth 设备名称更改 [英] CoreBluetooth device name change
问题描述
我目前正在创建一个简单的 iOS 蓝牙应用程序.我目前有一个能够修改名称的设备.我发现当我连接到 CBPeripheral 设备时,它似乎正在缓存旧设备名称.
I am currently creating a simple iOS bluetooth app. I currently have a device with the ability to modify the name. What I am finding is that when I connect to a CBPeripheral device, it seems to be caching the old device name.
- 通过我的应用连接到设备.
- 通过我的应用与设备断开连接.
- 更改设备名称.
- 通过我的应用(使用现有的 CBPeripheral 对象)重新发现/重新连接到设备.
按照上述步骤,我希望我的 iOS 应用程序能够发现新的设备名称.但是,我发现它倾向于保留旧名称.通过两次断开与 CBPeripheral 设备的连接,我发现我可以检索新名称.
By following the procedure above, I was expecting my iOS app to discover the new device name. However, I am finding that it has a tendency of retaining the old name instead. By disconnecting from the CBPeripheral device twice, I find that I can retrieve the new name.
所以我的问题是,有没有办法更新或清除 CBPeripheral 现有的已发现特征(或每次重新发现新特征)以获得最新的设备名称?
So my question is, is there a way to update or clear CBPeripheral's existing discovered characteristics (or rediscovering new characteristics each time) in order to get the latest device name?
这里有一个类似的问题:CoreBluetooth:刷新本地名称一个已经发现的外设
Here is a similar issue: CoreBluetooth: Refreshing local name of an already discovered Peripheral
推荐答案
我也遇到了类似的问题,而且不仅仅是设备名称的问题,而是在特定模式下某些特性发生了变化(例如设备上的固件升级).
I had a similar issue, moreover it wasn't a problem only with the device's name but some characterstics changed in specific modes (like firmware upgrade on a device).
从苹果那里得到了以下答复:
答案是配件需要支持 GATT Service Changed 特性 - 请阅读 规范,特别是第 3 卷 G 部分 2.5.2 和第 3 卷 G 部分 7.1."
Got the following answer from apple:
"The answer is that the accessory needs to support the GATT Service Changed characteristic - please read the specification, specifically Vol 3, Part G, 2.5.2, and Vol 3, Part G, 7.1."
名称问题已通过将设备名称作为广告数据中的属性进行广告来解决.(然而,这可能需要特定的固件,因为它并不总是在 adv 包中具有该属性)
The name issue has been solved by having the device name advertised as a property in the advertisement data. (This however might need specific firmware as it doesn't always have that property in the adv package)
否则要重置核心蓝牙缓存:您将需要重新启动 iOS 蓝牙适配器,我无法在 iOS 上以编程方式执行此操作.
Otherwise to reset the core-bluetooth cache: you will need to re-start the iOS bluetooth adapter which I couldn't manage to do programatically on iOS.
这篇关于CoreBluetooth 设备名称更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!