Hello everyone,
I’m trying to check the network status with the cordova-plugin-network-information plugin.
This is my actual code :
isOnline: boolean = false;
constructor(platform: Platform) {
platform.ready().then(() => {
document.addEventListener('offline', this.onNetworkDisconnect, false);
document.addEventListener('online', this.onNetworkConnect, false);
})
}
private onNetworkDisconnect(): void {
this.isOnline = false;
console.log('Connection lost!', this.isOnline, Network.connection);
}
private onNetworkConnect(): void {
setTimeout(function() {
this.isOnline = Network.connection != Connection.NONE;
console.log('Connection restored!', this.isOnline, Network.connection);
}, 2000);
}
I can’t figure out why but i never reach the onNetworkDisconnect() function. However when i turn airplane mode off the onNetworkConnect() works fine.
Tested on 2 different Android devices : 6.0.1 and 5.0.2 and the same problem occurs.
Ionic Info :
Cordova CLI: 6.2.0
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
OS: Distributor ID: Arch Description: Arch Linux
Node Version: v5.12.0
network-information plugin : v1.2.1
(Also tested on macOS, same issue)
If you have any suggestions and/or informations that would be great !
Thanks.