Home > OS >  How to cancel pending local connection to a peripheral
How to cancel pending local connection to a peripheral

Time:10-30

Hello I am new to iOS community. I want to cancel pending local connection to a peripheral. I know the code for cancel connection for active peripheral. If peripheral is active then we can pass connected peripheral as a parameter in following.

Central manager.cancelPeripheralConnection(connectedPeripheral)

but how to cancel pending local connection to a peripheral.

CodePudding user response:

As Michael Kotzjan said, cancelPeripheralConnection can be used to cancel a pending BLE connection. Unfortunately there isn't a way to know the peripheral to which you are trying to connect apart from saving the peripheral's UUID in the app yourself. In other words, when trying to connect to a peripheral, save the peripheral UUID (e.g. peripheralUuidBeingConnectedTo) - and then when cancelling the pending connection, use the peripheral UUID that you saved.

The reason why this information isn't saved is because you might be trying to connect to multiple peripherals at the same time. So when calling cancelPeripheralConnection, CoreBluetooth needs to know the ID of the device you are attempting to connect to.

Have a look at the links below for more info:-

  • Related