In Ionic 4 while watching if the network connection is back or not using an ionic plugin for background mode, it is not working, it is activating the background mode but network subscribe is not working.
import { BackgroundMode } from '@ionic-native/background-mode/ngx';
import { Network } from '@ionic-native/network/ngx';
private backgroundMode: BackgroundMode,
private network: Network,
console.log('net connected at ' + moment().format('YYYY-MM-DD hh:mm:ss')) is called only after app comes in forground
this.backgroundMode.enable();
this.bgSubscription = this.backgroundMode.on('activate').subscribe(() => {
console.log('active'); //going here
this.bgNetworkSubscription = this.network.onConnect().subscribe(() => {
// not going inside this while app is in background
console.log('net connected at ' + moment().format('YYYY-MM-DD hh:mm:ss'));
});
});
I am using
@ionic-native/background-mode": "^5.23.0",
@ionic-native/network": "^5.23",
Ionic CLI : 5.4.16
@angular/cli : 8.3.25
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)