Page 1 of 1

Scan for BLE devices in the background?

Posted: 00:19, 10 Nov 2015
by andersjj
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.

Re: Scan for BLE devices in the background?

Posted: 13:33, 11 Dec 2015
by alex

Re: Scan for BLE devices in the background?

Posted: 11:10, 16 Dec 2015
by micke
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

Re: Scan for BLE devices in the background?

Posted: 11:13, 16 Dec 2015
by micke
Created an issue for adding iOS background modes to the BLE plugin: https://github.com/evothings/cordova-ble/issues/85

Re: Scan for BLE devices in the background?

Posted: 11:29, 16 Dec 2015
by micke
Only bluetooth-central would be needed for the BLE central role (the plugin does not yet support peripheral role on iOS).