Cordova network isOnline returns true only on WiFi

2019-02-07 12:49发布

The following logs out only when I have WiFi on. On 4g or any mobile internet type it doesn't. Doesn't seem so reliable. Any ideas for a better detection of online/offline state?

$rootScope.$on( '$cordovaNetwork:online', function ( event, networkState ) {
    console.log( "Phone is online" );
} );

1条回答
Juvenile、少年°
2楼-- · 2019-02-07 13:14

This works fine for me:

function isOnline(){
     return !(Connection.NONE==navigator.connection.type);
}

I hope this helps you!

查看更多
登录 后发表回答