Background mode for BLE app

Hi. I have medical app that communicates with bluetooth device all the time monitoring heart rate and oxygen. I set it as background: External accessory communication, Uses BLE, Background fetch, Remote notifications, Background processing. Unfortunately after about an hour max 2 hours it stops communicating with bluetooth device and stops sending data to the server. I know in Android for example if device in similar to iOS background mode but phone plugged into power then app will never be suspended. Is there some way for the app to be always running? We can tell users to keep it powered or always in foreground.

Please help.

Have you set scanOptions?

let UUIDs: [CBUUID] = [systemServiceUUID]
let scanOptions = [CBCentralManagerScanOptionAllowDuplicatesKey: true]
centralManager.scanForPeripherals(withServices: UUIDs, options: scanOptions)

But even if you set it, I don't think iOS will allow you to connect permanently like Android does, just for a longer connection time. Please give up on the idea of a completely permanent connection.

I assume when you say stops communicating with the Bluetooth device, you mean the connection was dropped? This is different from the connection continuing to exist and you just stop receiving notifications/indications.

When you see your device disconnect, just issue a reconnect and upon connection, go through your gatt discovery procedure again as if it was a fresh connection. Lose all of your characteristic references and start over to be sure.

Background mode for BLE app
 
 
Q