Hi team,
unable to find whether the app is already connected to network or not.
I tried with ionic network native plugin but it gives network status only on an event such as network change, disconnection and on a new connection if network was disconnected on app start.
checkForNetwork(){
console.log(“NETWORK SERVICE”,this.network,this.network.type)
return new Promise((resolve,reject)=>{
this.connected = this.network.onConnect().subscribe(data => {
console.log(“onlineeee”,data)
this.networkDetail.connected=true;
this.networkDetail.networkType=this.network.type;
resolve(this.networkDetail)
this.displayNetworkUpdate(data.type);
}, error =>{ console.log(error)
resolve()
});
this.disconnected = this.network.onDisconnect().subscribe(data => {
console.log(data)
this.networkDetail.connected=false;
this.networkDetail.networkType=this.network.type;
reject(this.networkDetail)
this.displayNetworkUpdate(data.type);
}, error =>
{ console.log(error)
resolve()
});
})
}
Goal : check if network is available then call api otherwise show error
Thanks