cordova-plugin-background-mode icon indicating copy to clipboard operation
cordova-plugin-background-mode copied to clipboard

won't work Ionic 5 - angular 9

Open jdlopezq opened this issue 5 years ago • 10 comments

Hi i'm trying to make this work

this.backgroundMode.enable()

this.backgroundMode.on('activate').subscribe(() => { this.splashScreen.show() }) this.backgroundMode.on('deactivate').subscribe(() => { this.splashScreen.hide() })

but when I install this on the phone it doesn't work, its like the code runs when the app comes on foreground so it shows the splash screen when gets back on foreground and disappears after a few seconds, but i need to show the splash screen when the app its on the background. Thanks i hope someone can help me :)

Ionic:

Ionic CLI : 6.9.1 (/Users/juand.lopez/.nvm/versions/node/v10.16.0/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.0.0-rc.5 @angular-devkit/build-angular : 0.900.5 @angular-devkit/schematics : 9.0.5 @angular/cli : 9.0.5 @ionic/angular-toolkit : 2.0.0

Cordova:

Cordova CLI : 9.0.0 ([email protected]) Cordova Platforms : android 8.1.0, ios 5.1.1 Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 22 other plugins)

Utility:

cordova-res (update available: 0.15.1) : 0.6.0 native-run (update available: 1.0.0) : 0.2.8

System:

Android SDK Tools : 26.1.1 (/Users/juand.lopez/Library/Android/sdk) ios-deploy : 1.9.4 ios-sim : 8.0.2 NodeJS : v10.16.0 (/Users/juand.lopez/.nvm/versions/node/v10.16.0/bin/node) npm : 6.14.5 OS : macOS Catalina Xcode : Xcode 11.5 Build version 11E608c

jdlopezq avatar Sep 01 '20 21:09 jdlopezq

Hi,

Exactly what are you trying to do? Because, I am using angular 9 and Ionic5, and it seems to work:

 this.backgroundMode.enable();
      this.backgroundMode.disableWebViewOptimizations();
      console.log('BACKGROUND');
      console.log(this.backgroundMode.isEnabled());
      this.backgroundMode.on('activate').subscribe(r => {
        this.backgroundMode.disableWebViewOptimizations();
        this.backgroundMode.disableBatteryOptimizations();
        // console.log('ONACTIVATE');
        // console.log('STATUS BACKLOCATION');
        this.intervalId = interval(60000);
        this.intervalSub = this.intervalId.subscribe(() => {
          // console.log('PRUEBA PRUEBA');
          this.backgroundMode.wakeUp();
          this.geolocation.getCurrentPosition().then(r => {
            // console.log('UBICACIONI');
            console.log(r.coords.latitude);

alexisqc92 avatar Sep 05 '20 00:09 alexisqc92

Hi! @alexisqc92 I'm trying to hide some information when the app goes to background, so, the main goal it shows the splash screen before the app goes background, and hide it again once it comes to the foreground, something like this:

image

image image

Thanks!!!

jdlopezq avatar Sep 07 '20 16:09 jdlopezq

I have the same problem in ios, when it goes to brackground it does not detect the "activate" event, but if it detects the foreground event "deactivate", can someone give me a clue to solve it?

DiSaK74 avatar Sep 11 '20 10:09 DiSaK74

@jdlopezq where you able to make it work? Try print a console log, probably the problem can be the splash screen. Do you have the method on app.ts?

alexisqc92 avatar Sep 12 '20 05:09 alexisqc92

Yes, i have the method on app.ts and my code is simple:

this.backgroundMode.enable();

this.backgroundMode.on('activate').subscribe(r => { //no work
console.log('ONACTIVATE'); }

this.backgroundMode.on('deactivate').subscribe(r => { //yes work
console.log('DEACTIVATE'); }

when I put this line everything works correctly: this.backgroundMode.disableWebViewOptimizations();

this.backgroundMode.enable(); this.backgroundMode.disableWebViewOptimizations();

this.backgroundMode.on('activate').subscribe(r => { //yes work
console.log('ONACTIVATE'); }

this.backgroundMode.on('deactivate').subscribe(r => { //yes work
console.log('DEACTIVATE'); }

DiSaK74 avatar Sep 14 '20 07:09 DiSaK74

Could you try: https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/

danielehrhardt avatar Sep 15 '20 14:09 danielehrhardt

Could you try: https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/

that worked for me, thanks !!

Metecko avatar Sep 15 '20 20:09 Metecko

Could you try: https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/

This git has a lot of new code and pull request merged, this should be the official one, it is well maintained

jmesa-sistel avatar Sep 24 '20 17:09 jmesa-sistel

I believe you have to call setDefaults first but I am testing on Android. Once I setDefaults it worked.

        this.backgroundMode.setDefaults({
            text: "Test",
            title: "Test",
            icon: "my_icon",
        });

tellybrown avatar Jan 10 '21 04:01 tellybrown

The problem with that plugin "https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/" is when I put “cordova.plugins.backgroundMode.enable ();” in the code I have an error of: “Property ‘backgroundMode’ does not exist on type ‘CordovaPlugins’.”

Thank you

dobleM20 avatar Jul 17 '21 19:07 dobleM20