0

根據網絡連接我想顯示不同的內容,所以我想確定一個設備是否支持4G或3G連接。我怎樣才能做到這一點?我試圖尋找解決方案,但一直未能找到任何東西。如何確定設備是否支持4G?

回答

1

您可以使用cordova-plugin-network-information插件來檢查用戶的當前的網絡狀態

$ionicPlatform.ready(function() { 
     var networkState = $cordovaNetwork.getNetwork(); 
     console.log('network state: ',networkState); 
     if (networkState == Connection.CELL_4G) { 
      //show the contents to the user while user is in 4g 
     }else{ 
      //show the contents to the user if not 4g 
     } 
    }) 

網絡狀態的值有

  • Connection.WIFI
  • Connection.CELL_2G
  • Connection.CELL_3G
  • Connection.CELL_4G
  • Connection.NONE
  • Connection.CELL
  • Connection.UNKNOWN
  • Connection.ETHERNET
相關問題