Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving data when app is in background #254

Open
flaviosuardi opened this issue Mar 24, 2021 · 0 comments
Open

Receiving data when app is in background #254

flaviosuardi opened this issue Mar 24, 2021 · 0 comments

Comments

@flaviosuardi
Copy link

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.

Device, Build, OS:
all iOS devices, iOS14

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant