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!