在 Ionic 4 中,在查看网络连接是否恢复或没有使用 ionic 插件作为后台模式时,它不起作用,它正在激活后台模式但网络订阅不起作用。
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')) 仅在应用程序进入前台后调用
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'));
});
});
我在用
@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)