Reputation: 388
I am making an app for a custom Bluetooth device. The app connects/communicates correctly with the device, however some strange connection/reconnection problems occur sometimes.
One reproducible situation of this issue is when the battery dies:
This is how the manager in step 8 is initiated:
fileprivate override init() {
super.init()
self.manager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey : Constants.cbCentralManagerOptionRestoreIdentifierKey])
}
Question: Does anyone know what the cause of this could be? Or what the fix is?
Possible Clues:
I need to select Forget the device twice to forget the device in Apple's BT Settings (after the first time forgetting, the device is still connected with the info button displayed)
I have background bluetooth enabled
I get the following message in my debugger:
[CoreBluetooth] XPC connection invalid
Upvotes: 0
Views: 1120
Reputation: 1225
If your BLE device get disconnected then you need to call this function
[centralObj connectPeripheral:peripheral options:nil];
in didDisconnectPeripheral in delegate methods. You don't need to call scanForPeripheralsWithServices every time.
Upvotes: 0