Application does not detect services when reconnecting after turning on bluetooth power

When I switch bluetooth when connected to a CoreBluetooth peripheral, I do disconnect and delete all the links to my peripheral device in the centralManagerDidUpdateState .

Performing another scan will find and reconnect to the device and return discoverServices again, but this time around didDiscoverServices never happens. Having deleted all the settings (General β†’ Reset β†’ Reset all settings) or restart it again. Disconnecting / reconnecting, as usual, also works. How can I get around this or delete all cache and UUIDs saved by iOS programmatically?

+4
source share
2 answers

When you receive a callback in which the state of centralManager has changed to CBCentralManagerStatePoweredOff , you need to scroll through all your peripherals and call cancelConnection: on them. Then you will be fine.

 [_yourCentralManager cancelPeripheralConnection:yourPeripheral]; 
+1
source

If the central state is CBManagerStatePoweredOn , and call the cancelPeripheralConnection API as follows:

 [self.centralManager cancelPeripheralConnection:self.peripheral]; 

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

0
source

Source: https://habr.com/ru/post/1494461/


All Articles