Scan for BLE devices in the background?

Ask, and ye shall receive.
andersjj
Posts: 7
Joined: 20:17, 31 Oct 2015

Scan for BLE devices in the background?

Postby andersjj » 00:19, 10 Nov 2015

Wondering if the Evothings cordova BLE plugin is capable of running in the background and discovering devices while in background mode?

I updated my Cordova project to run in the background and I can confirm it's running via some console.logs in the code.

I also update the Objective C code in the BLE plugin to NSLog when it discovers a BLE device.

Interestingly enough, when the app goes into the background, the BLE NSLogs stop, while the logs from the Corodva app continue. The app continues to run, but no BLE devices are showing as discovered in the background.

I was wondering if this is just not possible, or if there is some config, etc. that I might need to do.

I already have the bluetooth-central entry in the plist for required background modes, but it doesn't seem to be helping.


BTW - I know this has some App Store implications, but right now I'm just trying to see if I can get it to work in any way.

alex
Posts: 92
Joined: 00:59, 19 Nov 2013

Re: Scan for BLE devices in the background?

Postby alex » 13:33, 11 Dec 2015


User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Scan for BLE devices in the background?

Postby micke » 11:10, 16 Dec 2015

Hi, it is definitely possible to scan in the background. What is needed is to add some definitions to the plugin.xml file.

For iOS, this is not currently added, but the plan is to do that. As I recall background mode already works on Android.

You can add the background modes required by iOS if you build your own Cordova app.

Edit the platform section for "ios" in plugin.xml in cordova-ble as follows:

Code: Select all

   <platform name="ios">
      <config-file target="config.xml" parent="/*">
         <feature name="BLE">
            <param name="ios-package" value="EVOBLE"/>
         </feature>
      </config-file>
      
      <config-file target="*-Info.plist" parent="UIBackgroundModes">
         <array>
            <string>bluetooth-central</string>
            <string>bluetooth-peripheral</string>
         </array>
      </config-file>

      <framework src="CoreBluetooth.framework" />

      <header-file src="src/ios/EVOBLE.h" />
      <source-file src="src/ios/EVOBLE.m" />
   </platform>


It is the "UIBackgroundModes" that is added.

You would also need a notification plugin, such as this one: https://github.com/katzer/cordova-plugi ... ifications

Had some problems with this plugin to build on iOS, this is also on the todo-list to fix.

Best regards, Mikael

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Scan for BLE devices in the background?

Postby micke » 11:13, 16 Dec 2015

Created an issue for adding iOS background modes to the BLE plugin: https://github.com/evothings/cordova-ble/issues/85

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Scan for BLE devices in the background?

Postby micke » 11:29, 16 Dec 2015

Only bluetooth-central would be needed for the BLE central role (the plugin does not yet support peripheral role on iOS).


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 47 guests