Apple now supports background services in iOS 4 and above, meaning your apps can now run code in the background much like Android apps are able to. In this recipe we are going to create a background service, which will execute a set piece of code from a separate file called bg.js
. We will also log each stage of the background service cycle to the console so you can understand each process.
Open your project's app.js
file in your IDE and enter in the following code (deleting any existing code):
//create root window var win1 = Titanium.UI.createWindow({ backgroundColor: '#fff', title: 'Background Services' }); function validiOSPlatform() { //add iphone checks if (Titanium.Platform.osname == 'iphone') { var version = Titanium.Platform.version.split("."); var major = parseInt(version[0],0); //can only test this support on...