问题描述
当我连接到 CoreBluetooth 外围设备时切换蓝牙时,我在 centralManagerDidUpdateState centralManagerDidUpdateState中断开并删除了对我的外围设备的所有引用回调。
When I am toggling bluetooth while connected to a CoreBluetooth peripheral I do a disconnection and deletion of all references to my peripheral in the centralManagerDidUpdateState callback.
执行另一次扫描会找到并重新连接到设备并再次发出 discoverServices ,但这次是围绕回调 didDiscoverServices 永远不会发生。通过删除所有设置(常规 - >重置 - >重置所有设置)或重新启动它再次工作。正常断开/重新连接也有效。我如何解决这个问题或以编程方式删除iOS存储的所有缓存和UUID?
Doing another scan will find and reconnect to the device and again issue a discoverServices, but this time around the callback didDiscoverServices never happens. By deleting all settings (General -> Reset -> Reset all settings) or do a reboot it works again. Disconnect/reconnect as normal does also work. How can I work around this or delete all cache and UUID's stored by iOS programatically?
推荐答案
当你得到centralManager的回调时状态已更改为 CBCentralManagerStatePoweredOff ,您需要遍历所有外围设备并在其上调用 cancelConnection:。那你就好了。
When you get the callback that the centralManager state has changed to CBCentralManagerStatePoweredOff, you need to loop through all your peripherals and call cancelConnection: on them. Then you'll be good to go.
[_yourCentralManager cancelPeripheralConnection:yourPeripheral];
这篇关于电源循环蓝牙后重新连接时,应用程序不会发现服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!