ionic 下获取手机的网络状态
项目中 需要在请求接口前 先判断手机的网络状态 网上查了下资料 这边总结个方法:
checkNetwork() {
let newVariable: any;
newVariable = window.navigator;
var networkState = newVariable.connection.type;
alert(networkState);
}
注意 直接用window.navigator.connection 会报错 ‘Property connection does not exist on type navigator’ 这个是因为typeScript的类型检查
所以先用变量承接下