Created
March 8, 2012 02:08
-
-
Save minhnc/1998064 to your computer and use it in GitHub Desktop.
iOS: Background Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var service = Titanium.App.iOS.registerBackgroundService({ | |
url: 'bgservice.js' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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