V. Pivet V. Pivet - 1 year ago 290
Android Question

Ionic 2 : Run a background task

I try to create a background task for my Ionic 2 app. I found this :
https://ionicframework.com/docs/v2/native/background-mode/

But my IDE doesn't found "backgroundMode" in this line :

cordova.plugins.backgroundMode.enable();


I have install the plugin.

Q : What I have to do to create a function who run when my user doesn't use the app.
And why I have this error ?

Thanks for your help.

Answer Source

Cordova plugins only work in devices. You can not use them on browser during development.

If you want to test that plugin, you should run your app with ionic run android (or ios) with a device plugged to PC or use an emulator. You can also run ionic build and install the debug package on a device.

In development, you can declare cordova variable with declare var cordova:any; at begining of script to avoid IDE errors of cordova being an undefined variable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download