Open jdlopezq opened 4 years ago
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);
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:
Thanks!!!
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?
@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?
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');
}
Could you try: https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/
that worked for me, thanks !!
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
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",
});
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
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 (cordova-lib@9.0.1) 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