O'Reilly logo

Appcelerator Titanium Smartphone App Development Cookbook - Second Edition by Jason Kneen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a background service on an iPhone

Since iOS 4, Apple has supported background services, which means your apps can now run code in the background, much like Android apps (however, there are some limitations as well as workarounds). In this recipe, we are going to create a background service that 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. Thus, you will understand each part of the process.

How to do it…

Open your project's app.js file and enter the following text (deleting any code that exists):

//create root window var win1 = Ti.UI.createWindow({ backgroundColor : '#fff', title : 'Background Services' }); //register a background service. //this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required