BLE Multitasking not working as expected

Hi,


our company is working on an app that involves an external device and communicate with it using BLE protocol.

This device is for medical purpose, its kind an earphone which retrieves electro information and sends to mobile in order to try to detect an epileptic crisis before it happens. People who buy the device and download the app are completely aware of that, and in first versions of the app, it will only retrieve data, so we can optimize the prediction analysis algorithm, and launch an app update with real time prediction on it.


So this is what we do, once the app is connected to the device, it starts sending data to app all the time and the app stores it and periodically uploads this data to a server, which stores it. The problem we have, is that even we declare the app needs to work in background mode, after a few seconds after it enters in background, stops working cutting all communication with the device.


Reading the docs it doesn't appear we are doing anything wrong, it's just that it seems that's the way it should work, and if we need to do something different, like stay permanently connected and retrieving data from the BLE device, we to do special request to you, or, I don't know maybe applying to MFI program or something similar.


So this is what this is all about, is there a way we can stay permanently connected to the device, even in background mode? DO we have to apply a special apple program?


I'd be very grateful if you could give me some directions about that.


Thank you!

Hi Santibj,


May I know is it possible to connect , pair and transfer data with external devices via bluetooth without joining MFI program?


Regards,

Arbind

Hi All,


May I know is it possible to connect , pair and transfer data with external devices via bluetooth PAN without joining MFI program?


Regards,

Arbind

arbind.yadav@gmail.com wrote:

May I know is it possible to connect, pair and transfer data with external devices via bluetooth PAN … ?

No. The only Bluetooth API for non-MFi accessories is Core Bluetooth, which is for Bluetooth LE. MFi accessories can use External Accessory framework. This supports ‘classic’ Bluetooth, but via a custom protocol (not Bluetooth PAN).

ps If you have follow-up questions about Bluetooth it’d be best to post them to the Core OS > Bluetooth topic area (in contrast, santibj fits here because it’s about multitasking).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

It should be possible to communicate with a Bluetooth LE peripheral while in the background. It’s hard to say what’s going on here without more details of how you have things set up. You wrote:

So this is what we do, once the app is connected to the device, it starts sending data to app all the time and the app stores it and periodically uploads this data to a server, which stores it.

Define “all the time”? How frequently is the peripheral sending updates to the central?

The problem we have, is that even we declare the app needs to work in background mode, after a few seconds after it enters in background, stops working cutting all communication with the device.

That do you mean by “the app needs to work in background mode”? Did add a

bluetooth-central
entry to the
UIBackgroundModes
array in your
Info.plist
?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks eskimo for clarifications.

Yes, we have this background mode in

UIBackgroundModes
array of the plist.
<key>UIBackgroundModes</key>
  <array>
  <string>bluetooth-central</string>
  <string>bluetooth-peripheral</string>
  <string>fetch</string>
  <string>remote-notification</string>
  </array>


This is what we do:

The app connects to device using BLE, after that, we stablish connection with a couple of characteristics, one is r/w, and the other one is readonly.


As soon as we are connected.


The app subcribes to receive notifications from those characteristics using:

peripheral.setNotifyValue(true, for: characteristic) peripheral.readValue(for: characteristic)

Then the app sends a command to the r/w one.

At the same time it starts receving data from the second one(readonly) at rate of 50Hz continuosly from this delegate:

func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)

(The data we receive is composed by 20 byte packages).


After that, the app should be connected to the device, receive and store all this packages even in background, but after aprox 90 seconds, the app stops.

With respect to this sequence of events, when does the app enter the background? Right at the beginning, before connecting to the device? Or after it’s connected while it’s continuing to receive this stream of notifications?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

after the last point, we do whole process with the app in foreground. Once the app starts receiving data we leave the phone, and 90 seconds after it enters in background the app stops receiving data.


Everyting works fine if the user don't let the phone sleep.

Traffic from a Bluetooth LE peripheral should be able to resume (or relaunch) your app in the background assuming a) you have things set up correctly, and b) you have the

bluetooth-central
background mode. I’m not sure what’s going on here, and I don’t even have any hints as to how you might debug it. My recommendation is that you open a DTS tech support incident and talk this over with our Bluetooth specialist.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
BLE Multitasking not working as expected
 
 
Q