question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'cordova.plugins.backgroundMode.onactivate is not a function' in Ionic 3 app

See original GitHub issue

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')
      })
    });
  }

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:27 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Genaritocommented, Jul 7, 2019

Thats the problem: using a forked version is always the solution

2reactions
MInesGomescommented, Apr 20, 2019

Is there any code to call besides backgroundMode.setDefaults({silent:false}) to make sure that the notification is instantiated?

Hi @rastographics

Maybe:

const options = {
      title: 'your title', text: 'your text',
      hidden: true, silent: false
    };
    this.plataform.ready().then(() => {
      cordova.plugins.backgroundMode.setDefaults(options);

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

cordova.plugins.backgroundMode.onactivate is not a function
For someone looking for the answer, like i do, with this code i could make it work using ionic v4: cordova.plugins.backgroundMode.enable(); ...
Read more >
Angularjs – Run ionic app in a background mode - iTecNote
I've recently implemented a feature like this in my project. I did use Ionic and I did use the Cordova plugin background mode...
Read more >
Location detection and HTTP call on background mode using ...
I have an ionic app in which the app behaves in the following way when it is in the foreground. ... function ()...
Read more >
cordova-plugin-background-mode-xjp - npm
Prevent apps from going to sleep in background.. Latest version: 0.7.3, last published: 2 years ago.
Read more >
Background Mode - Ionic Native
Cordova plugin to prevent the app from going to sleep while in background. Requires Cordova plugin: ... Checks if background mode is enabled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found