1

I'm working with beacons from Estimote. The cordova/phonegap plugin from Evothings is great!

Currently I try to monitor the regions if the application is in background. This works well, while the app is opened once and not killed after that.

At the moment I have the "startMonitoring" function called when the device is ready. I also tried to write the function outside the initialize-process, but it did not work at all.

So I'm searching for a solution even if the app is killed to send a notification to the user entering one of my regions.

Currently I'm testing on Android devices. I want to build the app for Android and iOS.

Here is my code:

var app = (function()
{
    // Application object.
    var app = {};

    // Dictionary of beacons.
    var beacons = {};

     app.initialize = function()
    {
        document.addEventListener('deviceready', onDeviceReady, false);
    };

    function onDeviceReady()
    {
        // Start tracking beacons in background
        startMonitoring();
    }

     function startMonitoring(){
        var myregion =
        {
            identifier: 'MyRegion',
            uuid: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXX5772XXXX',
            major : '12345',
            minor : '12346'
        };

        estimote.beacons.startMonitoringForRegion(
            myregion,
            function(state) {
                 console.log('Region state: ' + JSON.stringify(state));
                 $('#devRegion').html(state.state + ' ' + state.identifier);
            },
            function(errorMessage) {
                 console.log('Monitoring error: ' + errorMessage);
            }
        );
    }
    return app;
})();

app.initialize();

Is there a function to run a background service using cordova/phonegap?

Thank you!

dome12b
  • 583
  • 11
  • 32
  • Hah wow I'm searching for the same issue and posted on Stackoverflow this evening http://stackoverflow.com/questions/32616937/estimote-ibeacons-and-cordova-sending-push-notifications-when-app-is-killed-io . Not found anything yet but I've got it working when running in the background. You had any luck? – JamesG Sep 16 '15 at 19:55
  • Same here... Monitoring is working if the application is in background but not if the app is destroyed... – dome12b Sep 21 '15 at 07:56

1 Answers1

0

You can use the following Cordova/PhoneGap plugin to get background notifications on Android an iOS:

https://github.com/katzer/cordova-plugin-local-notifications

However, if you build using Cordova 5, be aware that this plugin does not yet support Cordova 5.

Here is a patched (but older) version of the plugin that supports Cordova 5 (note that the branch is evothings-master):

https://github.com/evothings/cordova-plugin-local-notifications/tree/evothings-master

To add this plugin use this command:

cordova plugin add https://github.com/evothings/cordova-plugin-local-notifications#evothings-master

Here is a tutorial that may be of help, it uses a generic iBeacon plugin, but should be relevant also for apps that use the Estimote plugin:

https://evothings.com/hands-on-guide-to-building-a-native-javascript-ibeacon-app-using-cordova/

Hope this helps!

Mikael Kindborg
  • 247
  • 2
  • 5
  • Thanks for the hint. Unfortunately the iBeacon-plugin seams to be the same as the estimote-plugin from evothings. Same functions, and still no background monitoring when the app is killed... – dome12b Sep 21 '15 at 08:11