Search code examples
iosreact-nativebluetooth-lowenergybackground-processreact-native-ios

React-native native module possibilities for background task on IOS


My Problem: I have an app that communicates with a medical BLE device. I have it all working but my problem is that when an ios user puts the app in the background I stop getting/processing the messages sent via bluetooth. Android seems to keep getting these messages but from what I've found, on iOS, the JS bridge is torn down and there isn't a solution out there for this problem. The phone must continue to process the data sent from the BLE device.

My thought is this and this is my question for you all. Would it be possible to create a native module for ios that will always be running and be doing the following: getting ble data as it is notified. Store that data to the file system and push it to a webservice all while the app is in the background? It would also be great to have the ability to read the fs created files and show some data about them when the app comes back to the foreground. Would this be possible?

Do you know of another option that could work?

Any help is greatly appreciated.


Solution

  • OK as I was heading down the native path and reading on the ios bluetooth schtuff I found this article Core Bluetooth Programming Guide and specifically it mentions a plist setting.

    The Core Bluetooth background execution modes are declared by adding the UIBackgroundModes key to your Info.plist file and setting the key’s value to an array containing one of the following strings: bluetooth-central —The app communicates with Bluetooth low energy peripherals using the Core Bluetooth framework. bluetooth-peripheral —The app shares data using the Core Bluetooth framework.

    So I thought to myself, would just by adding these keys to my xcode project that iOS would be smart enough and not care that I am a RN app and not native... well that was the ticket! I plugged these values in and the ble data is processed even when I open another app. "Wallah!" ;)