Skip to content

Instantly share code, notes, and snippets.

@minhnc
Created March 8, 2012 02:08
Show Gist options
  • Save minhnc/1998064 to your computer and use it in GitHub Desktop.
Save minhnc/1998064 to your computer and use it in GitHub Desktop.
iOS: Background Service
var service = Titanium.App.iOS.registerBackgroundService({
url: 'bgservice.js'
});
Ti.API.info('Background service started');
// now unregister it after 2 seconds
var stopTimeout = setTimeout(function() {
Ti.API.info('Background service stopping...');
Ti.App.currentService.stop();
Ti.API.info('Background service stopped!');
}, 2000);
Ti.App.currentService.addEventListener('stop', function() {
if(stopTimeout) {
clearTimeout(stopTimeout);
stopTimeout = null;
}
Ti.API.info('Background service stopped automatically!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment