• ngcordova 监控网络制式改变


    ngcordova 监控网络制式改变

    keywords

    cordova,phonegap,ionic,network,网络制式

    API参考

    http://ngcordova.com/docs/plugins/network/
    

    安装

    cordova plugin add cordova-plugin-network-information
    

    使用场景

    适用于但网络制式发生变化,需要动态改变APP运行参数,例如提醒网络切换,图片的加载,图片质量或者服务器API地址的切换。

    例子

    使用

    module.controller('MyCtrl', function($rootScope, $cordovaNetwork,$ionicLoading) {
      document.addEventListener("deviceready", function () {	
        //var type = $cordovaNetwork.getNetwork()
        var isOnline = $cordovaNetwork.isOnline()	
        var isOffline = $cordovaNetwork.isOffline()
    
        // listen for Online event
        $rootScope.$on('$cordovaNetwork:online', function(event, networkState){
    	  var type = $cordovaNetwork.getNetwork()
          var onlineState = networkState;
    	  if (type == Connection.WIFI) {
    		//TODO something
    	  }else if (type == Connection.CELL_4G || type == Connection.CELL_3G){
    	  	//TODO something
    	  }
        })
    
        // listen for Offline event
        $rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
          var offlineState = networkState;
    	  $ionicLoading.show({
              template: '网络异常,不能连接到服务器!'
          });
        })
    
      }, false);
    });
    

    Connection类型

    Connection.UNKNOWN
    Connection.ETHERNET
    Connection.WIFI	WiFi
    Connection.CELL_2G
    Connection.CELL_3G
    Connection.CELL_4G
    Connection.CELL
    Connection.NONE
  • 相关阅读:
    winform解析json API数据
    c#(winform)获取本地打印机
    winform程序post提交数据API
    C#关于panle重叠
    net面试总结的题目
    委托
    最实用JS 留着学习
    dev 控件获得所有的EFDEVGRID
    c#利用WebClient和WebRequest获取网页源代码的比较
    浅谈.Net WebService开发
  • 原文地址:https://www.cnblogs.com/sloong/p/5150342.html
Copyright © 2020-2023  润新知