this.network.onDisconnect().subscribe(() => {
console.log('network was disconnected :-(');
});
this.network.onConnect().subscribe(() => {
console.log('network connected!');
// We just got a connection but we need to wait briefly
// before we determine the connection type. Might need to wait.
// prior to doing any api requests as well.
setTimeout(() => {
if (this.network.type === 'wifi') {
console.log('we got a wifi connection, woohoo!');
}
}, 3000);
});
Have you Imported Network in app.module and added in provider?
And also call this function inside platform.ready in app.component
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
const connectSubscription = this.network.onConnect().subscribe(() => {
console.log('network connected!');
// We just got a connection but we need to wait briefly
// before we determine the connection type. Might need to wait.
// prior to doing any api requests as well.
console.log(this.network.type);
setTimeout(() => {
console.log(this.network.type);
if (this.network.type === 'wifi' ||
this.network.type === '4g'
) {
console.log('we got a connection, woohoo!');
}
}, 2500);
});
});
}
Same issue. The Network events are not beeing triggered.
Provided Network in AppModule
“@ionic-native/network”: “^5.11.0”,
“cordova-plugin-network-information”: “^2.0.2”,
“cordova-plugin-network-information”: {}