2013-10-08 08:28:55 +00:00
2014-11-17 13:06:54 +00:00
< p align = "right" >
< a href = "https://github.com/katzer/cordova-plugin-background-mode/tree/example" > EXAMPLE :point_right:< / a >
< / p >
2013-10-08 08:51:17 +00:00
2014-11-17 13:06:54 +00:00
Cordova Background Plug-in
==========================
2013-10-08 08:51:17 +00:00
2014-11-17 13:06:54 +00:00
[Cordova][cordova] plugin to prevent the app from going to sleep while in background.
2014-02-26 00:15:20 +00:00
2014-11-17 13:06:54 +00:00
Most mobile operating systems are multitasking capable, but most apps dont need to run while in background and not present for the user. Therefore they pause the app in background mode and resume the app before switching to foreground mode.
The system keeps all network connections open while in background, but does not deliver the data until the app resumes.
2013-10-08 08:51:17 +00:00
2014-11-17 13:06:54 +00:00
### Plugin's Purpose
This cordova plug-in can be used for applications, who rely on continuous network communication independent of from direct user interactions and remote push notifications.
2014-02-26 00:15:20 +00:00
2014-11-17 13:06:54 +00:00
### :bangbang: Store Compliance :bangbang:
The plugin focuses on enterprise-only distribution and may not compliant with all public store vendors.
2014-02-13 13:15:12 +00:00
2013-10-08 08:51:17 +00:00
2014-11-17 13:06:54 +00:00
## Overview
1. [Supported Platforms ](#supported-platforms )
2. [Installation ](#installation )
3. [ChangeLog ](#changelog )
4. [Using the plugin ](#using-the-plugin )
5. [Examples ](#examples )
6. [Platform specifics ](#platform-specifics )
7. [Quirks ](#quirks )
2014-02-26 00:15:20 +00:00
2014-11-17 13:06:54 +00:00
## Supported Platforms
- __iOS__
- __Android__
- __WP8__
2013-10-08 08:51:17 +00:00
2014-02-26 00:15:20 +00:00
2014-11-17 13:06:54 +00:00
## Installation
The plugin can either be installed from git repository, from local file system through the [Command-line Interface][CLI]. Or cloud based through [PhoneGap Build][PGB].
### Local development environment
From master:
```bash
# ~~ from master branch ~~
cordova plugin add https://github.com/katzer/cordova-plugin-background-mode.git
2014-02-26 00:15:20 +00:00
```
2014-11-17 13:06:54 +00:00
from a local folder:
```bash
# ~~ local folder ~~
cordova plugin add de.appplant.cordova.plugin.background-mode --searchpath path
2014-02-26 00:15:20 +00:00
```
2014-11-17 13:06:54 +00:00
or to use the last stable version:
```bash
# ~~ stable version ~~
cordova plugin add de.appplant.cordova.plugin.background-mode@0.5.0
2014-02-26 00:15:20 +00:00
```
2014-11-17 13:06:54 +00:00
### PhoneGap Build
Add the following xml to your config.xml to always use the latest version of this plugin:
```xml
2014-02-26 00:15:20 +00:00
< gap:plugin name = "de.appplant.cordova.plugin.background-mode" version = "0.5.0" / >
```
2014-11-17 13:06:54 +00:00
More informations can be found [here][PGB_plugin].
2014-02-13 13:22:21 +00:00
2013-12-01 13:06:04 +00:00
2014-11-17 13:06:54 +00:00
## ChangeLog
#### Version 0.6.0 (not yet released)
- [feature:] Android support
- [___change___:] Disabled by default
- [enhancement:] iOS does not require user permissions, internet connection and geo location anymore.
2013-10-10 10:38:32 +00:00
2014-11-17 13:06:54 +00:00
#### Further informations
- The former `plugin.backgroundMode` namespace has been deprecated and will be removed with the next major release.
- See [CHANGELOG.md][changelog] to get the full changelog for the plugin.
2013-10-09 12:16:00 +00:00
2013-10-08 08:51:17 +00:00
## Using the plugin
2014-11-17 13:06:54 +00:00
The plugin creates the object ```cordova.plugins.backgroundMode``` with the following methods:
2013-10-09 12:16:00 +00:00
2014-11-17 13:06:54 +00:00
1. [backgroundMode.enable][enable]
2. [backgroundMode.disable][disable]
2. [backgroundMode.configure][configure]
2013-10-09 12:16:00 +00:00
2014-11-17 13:06:54 +00:00
### Plugin initialization
The plugin and its methods are not available before the *deviceready* event has been fired.
```javascript
document.addEventListener('deviceready', function () {
// cordova.plugins.backgroundMode is now available
}, false);
```
### Prevent the app from going to sleep in background
To prevent the app from being paused while in background, the `backroundMode.enable` interface has to be called.
#### Further informations
- The background mode will be activated once the app has entered the background and will be deactivated after the app has entered the foreground.
- To activate the background mode the app needs to be in foreground.
2013-10-08 14:32:10 +00:00
2013-10-09 12:16:00 +00:00
```javascript
2014-11-23 12:03:51 +00:00
cordova.plugins.backgroundMode.enable();
2013-10-09 12:16:00 +00:00
```
2014-11-17 13:06:54 +00:00
### Pause the app while in background
The background mode can be disabled through the `backgroundMode.disable` interface.
#### Further informations
- Once the background mode has been disabled, the app will be paused when in background.
2013-10-09 12:16:00 +00:00
```javascript
2014-11-23 12:03:51 +00:00
cordova.plugins.backgroundMode.disable();
2013-10-09 12:16:00 +00:00
```
2014-11-17 13:06:54 +00:00
## Examples
The following example demonstrates how to enable the background mode after device is ready. The mode itself will be activated when the app has entered the background.
```javascript
document.addEventListener('deviceready', function () {
// Enable background mode
cordova.plugins.backgroundMode.enable();
// Android customization
cordova.plugins.backgroundMode.configure({ text:'Doing heavy tasks.'});
}, false);
```
2013-12-01 12:49:36 +00:00
## Platform specifics
2013-10-10 10:38:32 +00:00
2014-11-17 13:06:54 +00:00
### Android Customization
2013-10-10 10:38:32 +00:00
2014-11-17 13:06:54 +00:00
To indicate, that the app is executing tasks in background and being paused would disrupt the user, the plug-in has to create a notification while in background like a download progress bar.
2013-10-10 10:38:32 +00:00
2014-11-17 13:06:54 +00:00
The title, ticker and text for that notification can be customized in the following way at any time:
```javascript
cordova.plugins.backgroundMode.configure({
title: String,
ticker: String,
text: String
})
```
2014-03-10 08:06:38 +00:00
2014-11-17 13:06:54 +00:00
By default the app will come to foreground when taping on the notification. That can be changed also.
```javascript
cordova.plugins.backgroundMode.configure({
resume: false
})
```
2013-12-01 12:49:36 +00:00
## Quirks
2014-11-17 13:06:54 +00:00
### iOS Crash
If the app crashes after installing the plugin, make sure that your `*-Info.plist` is valid and reset all occurences of blank strings
2013-12-01 12:49:36 +00:00
```xml
< key > NSMainNibFile< / key >
< string >
< / string >
```
2014-11-17 13:06:54 +00:00
2013-12-01 12:49:36 +00:00
to
2014-11-17 13:06:54 +00:00
2013-12-01 12:49:36 +00:00
```xml
< key > NSMainNibFile< / key >
< string > < / string >
```
2013-12-01 12:57:36 +00:00
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
2013-12-01 13:06:04 +00:00
2014-11-17 13:06:54 +00:00
2013-12-01 13:06:04 +00:00
## License
2014-11-17 13:06:54 +00:00
This software is released under the [Apache 2.0 License][apache2_license].
© 2013-2014 appPlant UG, Inc. All rights reserved
[cordova]: https://cordova.apache.org
[CLI]: http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface
[PGB]: http://docs.build.phonegap.com/en_US/index.html
[PGB_plugin]: https://build.phonegap.com/plugins/490
[changelog]: CHANGELOG.md
[enable]: #prevent -the-app-from-going-to-sleep-in-background
[disable]: #pause -the-app-while-in-background
[configure]: #android -customization
[apache2_license]: http://opensource.org/licenses/Apache-2.0
[appplant]: http://appplant.de