Background Jobs

Background Jobs feature in Quantum Platform includes Background Fetch and Background Transfers.

Background Fetch

You can allow the application to fetch data from a network on regular basis while it is in a background state, with the background fetch capability in iOS 7 and later. This data can be utilized to keep the content of the application up-to-date and present it to the user when the user launches or re-opens the application. Also, the capability to support long running HTTP/HTTPS tasks like downloading large files if the application is in background state is supported.

  • In iOS version 7 and above, an app that retrieves content regularly from a network can ask the system for background execution time to check for new content.
  • An application developer who wishes to perform a background fetch can enable this feature in Quantum Visualizer IDE and register for the feature using kony.backgroundjob.registerBackgroundFetch. This API can be used to register predefined fetch job that can handle tasks like file download, upload, or a custom task.
  • kony.net.HttpRequest API supports background transfers. Tasks like upload or download from the network (HTTP/HTTPS) that are active even when the app is in background or suspended state is available in iOS.

Background Transfers

The purpose of the background transfer service is to allow long running network downloads or uploads to take place even when the associated application is placed in the background. Background transfers are supported in HTTP and HTTPS protocols.

Following are the features in Background Transfer: 

  • Uploads and downloads are managed by iOS
  • Unlike background fetch, background transfers have unlimited time.
  • It can be put in the queue anytime (foreground and background).
  • App is woken up to handle authentication challenges, errors if any, or completion of the job.
  • Background transfer tasks can be paused and resumed.
  • Only HTTP and HTTPS protocols are supported.

Background Fetch Workflow

iOS 7 and later contains the Background Fetch API which allows an app to get updated content when the app is in background. iOS schedules the background fetch events based on the app usage so that the content is always up-to-date when user opens the application. iOS provides 30 seconds time frame for the app to wake up, fetch new data, update its interface, and go back to sleep.

If the Background Fetch feature is enabled in an app, the system wakes the app in the background from time to time and lets it go online to fetch new data with a goal to refresh its content. In this way the app is always up-to-date and users do not have to wait any more when they launch it.

The system determines how frequent the application can perform a background fetch and depends on the following factors:

  • If network connectivity is available at that particular time.
  • Is the device awake.
  • Data and time the application has taken in its previous attempt to perform a background fetch.

The iOS system gives power to an application to schedule Background Fetch. Background Fetch can also be used to perform tasks internally in the app. Only synchronous tasks must be performed in background fetch, other than long running Background Transfers that are asynchronous. After the task is done setBackgroundFetchCompletionStatus must be called, passing a result that indicates whether content is available.

Invoking setBackgroundFetchCompletionStatus tells the system that it can move the app back to the suspended state and evaluate its power usage.

Apps that download small amounts of content quickly and accurately reflect when they had content to download are more likely to receive execution time in the future than apps that take longer to download their content.

It is advisable to use Background Transfers supported by kony.net.HttpRequest in fetch task to optimally utilize the execution time provided in the Fetch task.

Background Fetch and Background Transfers APIs

Background Fetch APIs Background Transfer APIs

Following are the APIs for Background Jobs: 

Following are the Background Transfer APIs : 

Supported Versions and Platforms

The Background Job feature: 

  • Available in Quantum iOS platform versions above 5.6.2.
  • Supports iOS7 and the platforms above.
  • Supported only in JavaScript.