It’s a nice solution! Thanks!
But i have a problem when i need to check network status on app boot, it’s always returns null
.
Here is my code:
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { NetworkProvider } from '../providers/network/network';
import { NgZone } from '@angular/core';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage: any = 'LoginPage';
isOffline: boolean;
constructor(
platform: Platform,
statusBar: StatusBar,
splashScreen: SplashScreen,
public networkProvider: NetworkProvider,
public ngZone: NgZone
) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
statusBar.backgroundColorByHexString('#f6f6f6');
this.networkProvider.initializeNetworkEvents();
this.checkNetwork();
});
}
showOfflineAlert(data) {
this.ngZone.run(() => {
this.isOffline = !!data;
});
}
checkNetwork() {
this.networkProvider.getNetworkStatus().subscribe(data => {
console.log('platform ready', data);
this.showOfflineAlert(data);
});
}
}
Any thoughts guys? =D