watchOS: didDisconnectPeripheral not called in background

We have implemented a watchOS app that implements a CoreBluetooth central and as such connects to BLE peripherals. This works great when the watch app is in the foreground. When our peripherals disconnect, the didDisconnectPeripheral delegate method is properly called as expected.


However, when the watch is locked, or if our watch app goes to the background, the didDisconnectPeripheral is not being called when a peripheral disconnects.


The call occurs only when the watch app comes to the foreground again.


For our use case, we would like to re-connect to the peripheral if it gets disconnected regardless fo the state of the watch app.


For example, if the user goes in and out of BLE range, we want the watch app to automatically reconnect to the peripheral.


How we solve this on iOS is that as soon as didDisconnectPeripheral is called (for or background), we call central.connect(peripheral) immediately again, so that connection is reestablished when the peripheral comes back into BLE range.


So far, we have not been able to do this because of the above mentioned lack of call to didDisconnectPeripheral.


Can you provide some insights how this use cans can be implemented in watchOS?


Configuration: watchOS 4

Replies

When the app is running in the background, didDisconnectPeripheral is called, but once the app is being suspended, didDisconnectPeripheral, as any other delegate method, won't be called.


It would be very useful if Apple will add a

WKRefreshBackgroundTask
that will launch the watchOS app in the background and call the delelgate call.