安裝 插件 cordova plugin add cordova-plugin-network-information
支持平臺(Supported Platforms)
- Android
- Browser
- iOS
- Windows
注意事項 - <iOS7 can’t detect the type of cellular network connection.
- navigator.connection.type is set to Connection.CELL for all cellular data.
js 插件使用android
function checkConnection() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
checkConnection();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/281403.html
標籤:其他
