ionic 有无网络状态判断

**

ionic 有无网络判断

**
cordova-plugin-network-information 2.0.1
1 安装插件 cordova plugin add cordova-plugin-network-information

if (navigator.connection) {
    var tmptypes = navigator.connection.type;
    if (tmptypes.toUpperCase().indexOf('NONE') > -1 || tmptypes.toUpperCase().indexOf('UNKNOWN') > -1) {
       if (navigator.notification) {
           navigator.notification.confirm('您的设备未开启网络',function (buttonIndex) {
               if (buttonIndex == 1) {
                    if (cordova.plugins.settings) {
                        cordova.plugins.settings.openSetting("wifi", function () { console.log("network setting openning"); }, function () { console.log("open network setting failed"); });
                    }
               }
           }, // callback to invoke with index of button pressed
           '提示', // title
           ['开启', '取消'] // buttonLabels
           );
       }
    }
  }

猜你喜欢

转载自blog.csdn.net/weixin_43806483/article/details/84552909