App don't discover services when reconnecting after power cycling bluetooth

跟風遠走 提交于 2019-12-07 11:36:23

问题


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.

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?


回答1:


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];



回答2:


If the central state is CBManagerStatePoweredOn, and call the cancelPeripheralConnection API like this:

[self.centralManager cancelPeripheralConnection:self.peripheral];

the callback method centralManager:didDisconnectPeripheral:error: will be called. But if the state is not CBManagerStatePoweredOn, such as CBManagerStatePoweredOff, this callback will not execute.



来源:https://stackoverflow.com/questions/17966407/app-dont-discover-services-when-reconnecting-after-power-cycling-bluetooth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!