Hi, I'm trying to build an app to connect to both BR/EDR ("Classic") or BLE devices.
For Classic, the recommended flow in Apple docs is:
Start your app and initialize your CBCentralManager
Pair the phone and the device manually through settings
This should automatically call the connectionEventDidOccur
From then on it depends on the dev to choose what to do with the information from the callback (peripheral, event, etc), but the callback is simply never fired.
Here's my basic implementation of the callback:
func centralManager(_ central: CBCentralManager, connectionEventDidOccur event: CBConnectionEvent, for peripheral: CBPeripheral) {
print("IOS: connectionEventDidOccur for peripheral: %@", peripheral)
if (event == .peerConnected) {
print("IOS: Case is peer connected")
connectToPeripheral(peripheral.identifier.uuidString)
if(!savedPeripheralList.contains(where: { $0.identifier == peripheral.identifier })){
savedPeripheralList.append(peripheral)
}
} else if (event == .peerDisconnected ){
print("IOS: Peer %@ disconnected!", peripheral)
} else {
print("IOS: if statement didn't work")
}
}
I'm essentially:
Printing the fact that the callback was called
Trying to connect the app to the peripheral (by now only the phone is connected)
Saving this newly connected peripheral to a local list
For context, I've been able to scan and connect to BLE devices like earbuds normally, so my general implementation of other callbacks like didDiscover or didConnect works just fine, this is the only non functional callback.
Any ideas would be appreciated, thanks!