Search code examples
iosbluetoothbluetooth-lowenergycore-bluetooth

The app can't connect with new BLE device (iOS)


Our iOS app uses a specific Bluetooth device from a hardware partner. The device sends BLE packets periodically and the phone receives these packets and sends the data to our DB. It also works in the background. We occur the following problem: the user connects to the BLE device, uses the app, and when the app was in the background and user updates the app to the new version (when the app detected its update we programmatically disconnect the previous device), and when the user tries to connect to another new BLE device - app received:

Error Domain=CBATTErrorDomain Code=15 "Encryption is insufficient." UserInfo={NSLocalizedDescription=Encryption is insufficient.}

In iPhone settings previous device appears as Disconnected. For connecting to a new BLE device we create a new CBCentralManager with new generated CBCentralManagerOptionRestoreIdentifierKey If the force close the app and restarts again - the app is able to connect to the new BLE device. Maybe someone has seen something the same, or knows how it can be fixed without force closing?


Solution

  • I recommend you not create a new CBCentralManager when connecting to a new device. There really should only be one CBCentralManager in the app. My suspicion is that two connections with different parameters are being sent and confusing the device. This forums thread includes some good background on what that error means, though I don't think the problem discussed there is your problem. The fact that it works when you force-quit the app (thus ensuring there is exactly one CBCentralManager) matches what I'm suggesting.