Monitoring CBPeripheral Status Changes

So, there is a way to track state changes CBCentralManagerthrough centralManagerDidUpdateState(). But is there a similar method for monitoring state changes for CBPeripheral? I could not find anything in the library CoreBluetooth, and I want to call the function whenever it changes CBPeripheralState.

At the moment, all I have is a switch statement that checks the peripheral state, but will always return either connected or disconnected. How can I get to connect / disconnect cases? I tried to place the switch statement in different parts of my code, from method bleInit(), to startScanning(), connectToPeripheral(), etc.

switch(peripheral.state){
case .disconnected:
    print("disconnected")
case .connecting:
    print("connecting")
case .connected:
    print("connected")
case .disconnecting:
    print("disconnecting")
default: break
}
+4
2

. ; .

, CBCentralManager didConnect didDisconnectPeripheral.

+2

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


All Articles