capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

Capacitor network return always true connection status.

Open fahad-cinnova opened this issue 3 years ago • 3 comments

My current versions 1 - "@angular/core": "~10.0.0" 2 - "@capacitor/ios": "^3.4.3" 3 - "@capacitor/android": "^3.4.3" 4 - "@capacitor/core": "^3.4.3" 5 - "@capacitor/network": "^1.0.7"

app.component.ts File code below

import { Network } from '@capacitor/network';

async ngOnInit() { let status; const status = await Network.getStatus(); status = status.connected; Network.addListener('networkStatusChange',(val: any) => { if(val.connected){ status = status.connected; } }); } What's thing which missed from my side? It's returning only true connected status of network even i have not connected to any network.

Any one help me.

fahad-cinnova avatar Apr 30 '22 17:04 fahad-cinnova

check ConnectionType to see what is connected

jongbonga avatar Apr 30 '22 18:04 jongbonga

@jongbonga It's giving me "cellular". But now I'm using wifi so connectionType also return wrong.

fahad-cinnova avatar Apr 30 '22 18:04 fahad-cinnova

@jongbonga It's giving me "cellular". But now I'm using wifi so connectionType also return wrong.

Then status.connected is true is correct because you are connected. Don't confuse connected to the internet with connected to a Network. Cellular & Wifi are Network which is what the plugin checks.

Try to be on airplane mode then check again, connected should be equal to false

jongbonga avatar Apr 30 '22 19:04 jongbonga