Summary:
I am facing a problem related to the execution of very long BLE listen operation that cause problems when app is in background.
After a successfully connection I start to listen a characteristic with following code:
blueJay.listen(to: uartTxCharacteristic) { [weak self] (result: ReadResult<ReceivableMultipleDataPacket>) in
guard let self = self else {
return
}
switch result {
case .success(let multipleDataPacket):
self.log("<----: \(multipleDataPacket.rawData as NSData) == \(multipleDataPacket) >>> bytesReceived: \(self.bytesReceived)")
[here app make business logic stuff]
case .failure(let error):
self.log("error listening characteristic \(error)")
}
}
when I send a specific command to BLE peripheral, it starts to send me a lot of data and this operation takes several minutes because peripheral has to send me a lot of stuff. In this situation I can see data arrived in console but if I put app in background the operating system performs one of these two operations:
sometimes after 50-60 seconds kills the app with following error: Message from debugger: Terminated due to signal 9
sometimes puts the app in a kind of paused state, I cannot see any other data arrive in console and if I reopen app the operation seems to continue
I suppose the problem are iOS restrictions of background operations on iOS14 but have you ever faced this problem?
Do you know a way to allow app to continue receiving data in background?
I confirm that I have enabled "Uses BLE accessories" background mode.
In another app I have developed a BLE communication with a long time data transfer (about 10 minutes) but in that case BLE peripheral implements iBeacon protocol, in this app the receive data operation can be executed and completed also when app is in background. I suppose the reason is because iBeacon protocol that keep app alive with location updates.
Summary: I am facing a problem related to the execution of very long BLE listen operation that cause problems when app is in background.
After a successfully connection I start to listen a characteristic with following code:
when I send a specific command to BLE peripheral, it starts to send me a lot of data and this operation takes several minutes because peripheral has to send me a lot of stuff. In this situation I can see data arrived in console but if I put app in background the operating system performs one of these two operations:
Message from debugger: Terminated due to signal 9
I suppose the problem are iOS restrictions of background operations on iOS14 but have you ever faced this problem? Do you know a way to allow app to continue receiving data in background?
I confirm that I have enabled "Uses BLE accessories" background mode.
In another app I have developed a BLE communication with a long time data transfer (about 10 minutes) but in that case BLE peripheral implements iBeacon protocol, in this app the receive data operation can be executed and completed also when app is in background. I suppose the reason is because iBeacon protocol that keep app alive with location updates.
Device, Build, OS: all iOS devices, iOS14
Thanks for your help!