cordova-plugin-background-mode: 'cordova.plugins.backgroundMode.onactivate is not a function' in Ionic 3 app
I did a fresh install of this plugin using the Ionic V3 instructions (https://ionicframework.com/docs/v3/native/background-mode/). When I try to run the app in the simulator or device I get TypeError: cordova.plugins.backgroundMode.onactivate is not a function. (In 'cordova.plugins.backgroundMode.onactivate()', 'cordova.plugins.backgroundMode.onactivate' is undefined when I try to put the app in the background. It sees the subscription to the enable correctly. Any suggestions as to what is going wrong? I’ve the necessary import to app.module.ts.
Here is the code that is in the app.component.ts
import { BackgroundMode } from '@ionic-native/background-mode';
....
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, backgroundMode: BackgroundMode) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
backgroundMode.enable();
backgroundMode.on('enable').subscribe(() => {
console.log('enabled')
})
backgroundMode.on('activate').subscribe(() => {
console.log('activated')
})
});
}
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 3
- Comments: 27 (2 by maintainers)
Thats the problem: using a forked version is always the solution
Hi @rastographics
Maybe:
@n1705771 How did you solved ‘cordova.plugins.backgroundMode.onactivate is not a function’ ?
I installed
https://github.com/lkonzen-garupa/cordova-plugin-background-mode
and add the code for wake_lock
Is working for android 5, 7 and 10 😃
thanks https://github.com/lkonzen-garupa/cordova-plugin-background-mode has fixed the error