GithubHelp home page GithubHelp logo

l3th2nh / cordova-plugin-background-mode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from katzer/cordova-plugin-background-mode

0.0 2.0 0.0 739 KB

A bunch of background mode plugins for Cordova 3.x.x

License: Apache License 2.0

Java 47.13% Objective-C 22.56% C# 17.53% JavaScript 12.77%

cordova-plugin-background-mode's Introduction

EXAMPLE 👉

Cordova Background Plug-in

Cordova plugin to prevent the app from going to sleep while in background.

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.

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.

‼️ Store Compliance ‼️

The plugin focuses on enterprise-only distribution and may not compliant with all public store vendors.

Overview

  1. Supported Platforms
  2. Installation
  3. ChangeLog
  4. Using the plugin
  5. Examples
  6. Platform specifics
  7. Quirks

Supported Platforms

  • iOS
  • Android
  • WP8

Installation

The plugin can either be installed from git repository, from local file system through the Command-line Interface. Or cloud based through PhoneGap Build.

Local development environment

From master:

# ~~ from master branch ~~
cordova plugin add https://github.com/katzer/cordova-plugin-background-mode.git

from a local folder:

# ~~ local folder ~~
cordova plugin add de.appplant.cordova.plugin.background-mode --searchpath path

or to use the last stable version:

# ~~ stable version ~~
cordova plugin add [email protected]

PhoneGap Build

Add the following xml to your config.xml to always use the latest version of this plugin:

<gap:plugin name="de.appplant.cordova.plugin.background-mode" version="0.5.0" />

More informations can be found here.

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.

Further informations

  • The former plugin.backgroundMode namespace has been deprecated and will be removed with the next major release.
  • See CHANGELOG.md to get the full changelog for the plugin.

Using the plugin

The plugin creates the object cordova.plugins.backgroundMode with the following methods:

  1. backgroundMode.enable
  2. backgroundMode.disable
  3. backgroundMode.configure

Plugin initialization

The plugin and its methods are not available before the deviceready event has been fired.

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.
window.plugin.backgroundMode.enable();

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.
window.plugin.backgroundMode.disable();

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.

document.addEventListener('deviceready', function () {
    // Enable background mode
    cordova.plugins.backgroundMode.enable();
    // Android customization
    cordova.plugins.backgroundMode.configure({ text:'Doing heavy tasks.'});
}, false);

Platform specifics

Android Customization

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.

The title, ticker and text for that notification can be customized in the following way at any time:

cordova.plugins.backgroundMode.configure({
    title:  String,
    ticker: String,
    text:   String
})

By default the app will come to foreground when taping on the notification. That can be changed also.

cordova.plugins.backgroundMode.configure({
    resume: false
})

WP8 Optimization

By default the plugin will track for geo updates while the application is in background and foreground. To stop tracking in foreground, the MainPage.xaml.cs file needs the following 2 methods:

// MainPage.xaml.cs

namespace your.own.namespace
{
    public partial class MainPage : PhoneApplicationPage
    {
        /// </summary>
        /// The page (the app) will enter the background and the background mode
        /// needs to be activated.
        /// </summary>
        protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            Cordova.Extension.Commands.BackgroundMode.Activate();
        }

        /// </summary>
        /// The page (the app) will enter the foreground and the background mode
        /// needs to be deactivated.
        /// </summary>
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            Cordova.Extension.Commands.BackgroundMode.Deactivate();
        }
    }
}

Quirks

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

<key>NSMainNibFile</key>
<string>

</string>

to

<key>NSMainNibFile</key>
<string></string>

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

License

This software is released under the Apache 2.0 License.

© 2013-2014 appPlant UG, Inc. All rights reserved

cordova-plugin-background-mode's People

Contributors

katzer avatar siebmanb avatar

Watchers

James Cloos avatar Bkascript avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.