mui.plusReady(function() {
if (mui.os.android) {
plus.screen.lockOrientation("portrait-primary");
}
document.addEventListener("netchange",onNetChange,false);
function onNetChange(){
//获取当前网络类型
var nt = plus.networkinfo.getConnectionType();
switch(nt){
case plus.networkinfo.CONNECTION_ETHERNET:
case plus.networkinfo.CONNECTION_WIFI:
mui.toast("当前网络为WiFi");
break;
case plus.networkinfo.CONNECTION_CELL2G:
case plus.networkinfo.CONNECTION_CELL3G:
case plus.networkinfo.CONNECTION_CELL4G:
mui.toast("当前网络非WiFi");
break;
default:
mui.toast("当前没有网络");
break;
}
}
报错:Uncaught TypeError: Object #<Object> has no method 'getConnectionType'
1 个回复
ItsPaster
應該是用getCurrentType? 我使用此示例是OK的
http://www.dcloud.io/docs/api/zh_cn/device.shtml#plus.networkinfo