2

Is there any complete sample about cordova plugin background mode?

I am get error 'backgroundMode' of undefined

https://github.com/katzer/cordova-plugin-background-mode

TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94
zafer
  • 21
  • 3

1 Answers1

0

I too had the same issue. Just got it solved.

I would advise you not to follow the Ionic Documentation.

Use the following code in CLI to install the plugin.

cordova plugin add https://github.com/katzer/cordova-plugin-background-mode.git

Then in your ionViewDidLoad() of the root of your app, you can write the following code:

ionViewDidLoad(){
    cordova.plugins.backgroundMode.enable();//Line 1
    console.log("BackgroundMode is Enabled!");//Line 2
    console.log(cordova.plugins.backgroundMode);//Line 3
}

Before this, you should declare cordova by following code after all your imports.

declare let cordova:any;

This one should help :)

gsthina
  • 1,090
  • 8
  • 22