Skip to content

Instantly share code, notes, and snippets.

@christocracy
Last active April 30, 2016 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christocracy/6b7d3ed8f56f1c7faa7897b2fe55ee7a to your computer and use it in GitHub Desktop.
Save christocracy/6b7d3ed8f56f1c7faa7897b2fe55ee7a to your computer and use it in GitHub Desktop.
Sample of new Background Geolocation scheduling schema.
bgGeo.configure({
.
.
.
schedule: [
'1 17:30-21:00', // Sunday: 5:30-9:00
'2-6 9:00-17:00', // Mon-Fri: 9am to 5pm
'2,4,6 20:00-12:00',// Mon, Web, Fri: 8pm to midnight (next day)
'7 10:00-19:00' // Sun: 10am-7pm
]
});
/**
* @event schedule
* @param {Object} state
*/
bgGeo.on('schedule', function(state) {
console.log('- Schedule event, enabled:', state.enabled);
if (state.enabled) {
// tracking started!
} else {
// tracking stopped
}
});
// Start the Scheduler
bgGeo.startSchedule(function() {
console.info('- Scheduler started');
});
// Later when you want to stop the Scheduler (eg: user logout)
bgGeo.stopSchedule(function() {
console.info('- Scheduler stopped');
});
// Or modify the schedule with usual #setConfig method
bgGeo.setConfig({
schedule: [
'1-7 9:00-10:00',
'1-7 11:00-12:00',
'1-7 13:00-14:00',
'1-7 15:00-16:00',
'1-7 17:00-18:00',
'2,4,6 19:00-22:00'
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment