i have a project in ionic4, i am trying this codeg, but when execute in a real device not hidde loading when connect the internet in the phone, just show when not have internet
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private router:Router,
private menu:MenuController,
private logeo:LoginService,
private nvctr:NavController,
private activated_rout:ActivatedRoute,
private network:Network,
private loading_c:LoadingController
) {
this.network_check()
this.initializeApp();
}
network_check() {
// watch network for a disconnection
let disconnectSubscription = this.network.onDisconnect().subscribe(() => {
this.loading_present('mostrar')
});
// stop disconnect watch
disconnectSubscription.unsubscribe();
// watch network for a connection
let connectSubscription = this.network.onConnect().subscribe(() => {
this.loading_present('esconder')
// 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.
});
// stop connect watch
connectSubscription.unsubscribe();
}
async loading_present(condicion:String) {
const loading = await this.loading_c.create({
message: 'Esperando conectividad'
})
if(condicion == 'mostrar'){
loading.present()
}
else{
loading.dismiss()
}
}