Reputation: 2802
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?
Upvotes: 5
Views: 1043
Reputation: 351
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.
Upvotes: 0
Reputation: 13549
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];
Upvotes: 1