Titanium.App.iOS.BackgroundService

Object of Titanium.App.iOS.
Platform Since
iPhone 1.5
iPad 1.5

Summary

A background service that runs when the application is placed in the background.

Description

The BackgroundService is created by Titanium.App.iOS.registerBackgroundService. When creating a background service, you specify a local URL to a JavaScript file. The code in the JavaScript file is executed each time the background service runs.

The background service runs when the application is placed in the background and will continue to run until one of the following occurs:

  • The application resumes.

  • The service is stopped with the stop method.

  • The OS terminates the service for one of the reasons discussed in "Background Service Limitations", below.

Known Issues

Note that there are several issues with the current implementation of background services:

  • The background service runs when the Application is placed in the background and will continue to run until the service is stopped with the stop method, however, this also unregisters the service.

  • Calling unregister on the background service unregisters the service, but does not stop the background task under which the service was launched. This can lead to having multiple tasks running in the background.

  • Calling register multiple times with the same URL results in multiple instances of the same service being run.

These issues will be addressed in a future release. To work around these issues, the application must:

  • Unregister the background service when the application resumes.

  • Re-register the background service when the application pauses.

Background Service Limitations

Note that even with these workarounds, the background service is subject to limitations imposed by the operating system. In particular:

  • The OS limits the total amount of time the background service can run for after the application is suspended, typically to no more than 10 minutes.

  • The OS may terminate the background service at any point to reclaim resources.

Methods

Name Summary
addEventListener

Adds the specified callback as an event listener for the named event.

fireEvent

Fires a synthesized event to any registered listeners.

getUrl

Gets the value of the url property.

removeEventListener

Removes the specified callback as an event listener for the named event.

stop

Stops the service from running during the current background session to conserve resources.

unregister

Unregisters the background service.

Properties

Name Type Summary
url String

A local URL to a JavaScript file containing the code to run in the background. creation

Events

This type has no events.