问题
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:
This works fine for me:
function isOnline(){
return !(Connection.NONE==navigator.connection.type);
}
I hope this helps you!
来源:https://stackoverflow.com/questions/33878872/cordova-network-isonline-returns-true-only-on-wifi