Failed to reconnect after canceling BLE iOS peripheral connection

In my project, I managed to connect to the Bluetooth LE peripheral peripheral device and the finished value CBCharacteristicfrom this device. I ran into a problem. I need to disconnect the peripheral device and reconnect the device if I want.

I am using the following steps.

1. To disconnect : I'm calling centralManager?.cancelPeripheralConnection(peripheral). This call successfully completes the delegate callfunc centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?)

2. To reconnect : I run a scan for peripheral devices, as it was when I started the applicationcentralManager!.scanForPeripheralsWithServices(nil, options: nil)

But this call never calls a delegate func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber)where I try to connect a detected BLE peripheral.

My question is what is the best way to disconnect a BLE peripheral device and reconnect it again in iOS. Am I doing something wrong?

+4
source share
1 answer

This is not the right way to reconnect to BLE.

Per Documentation for Apple :

Reconnecting to peripherals

Using the basic Bluetooth infrastructure, you can connect to peripherals. You can:

  • - , , - retrievePeripheralsWithIdentifiers:. youre , .
    " ".
  • , retrieveConnectedPeripheralsWithServices:. , , , .
    .
  • , scanForPeripheralsWithServices:options:. , . " " , , .
+4

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


All Articles