V. Pivet
V. Pivet

Reputation: 1328

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.

Upvotes: 0

Views: 6395

Answers (1)

Ramon-san
Ramon-san

Reputation: 1097

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.

Upvotes: 2

Related Questions