【问题标题】:Fetching Connected WiFi Network Details In Ionic在 Ionic 中获取连接的 WiFi 网络详细信息
【发布时间】:2017-09-10 15:26:23
【问题描述】:

我正在从事一个基于 IOT 的离子项目。我需要在我的应用中获取已连接 WiFi 的详细信息(WiFi 名称和密码)。我有 used 这个插件。

cordova plugin add cordova-plugin-network-information

但是这个插件并没有提供很多信息,比如连接的WiFi的名称和密码。是否有任何插件或方法可以获取连接的WiFi详细信息? 谢谢

【问题讨论】:

    标签: android cordova ionic-framework phonegap-plugins


    【解决方案1】:

    我不知道这是否对您有帮助,但我使用了 cordova 插件:wifiwizard 和 cordova-plugin-networkinterface 来获取网络信息。在 iOS 上只能获取 SSID、BSSID、IP、已连接 WiFi 的子网和移动 IP,因为 Apple 的 Wifi 库 (Apple80211) 是私有的。

    我还使用 cordova 插件:cordova-plugin-x-toast 和 cordova-plugin-dialogs 来获取错误消息。

    以下方法readNetwork()将所有网络信息存储到$scope.wifi:

    // read network
    function readNetwork() {
        $scope.wifi = {};
    
        // get current SSID 
        WifiWizard.getCurrentSSID(
            function(ssid) {
                $scope.wifi.ssid = ssid.replace('"','').replace('"','');
    
                // update scope values in template
                $scope.$apply();
            }, 
            wifiError
        );
    
        // get current BSSID - ios only
        if(ionic.Platform.isIOS()) {
            WifiWizard.getCurrentBSSID(
                function(bssid) {
                    $scope.wifi.bssid = bssid;
    
                    // update scope values in template
                    $scope.$apply();
                }, 
                wifiError
            );
        }
    
        // get list of the available networks as an array of objects - android only
        if(ionic.Platform.isAndroid()) {
            WifiWizard.getScanResults(
                function(networks) {
                    $scope.wifi.networks = networks;
                    //console.log("networks: " + JSON.stringify(networks));
    
                    // find current bssid, if not available
                    networks.forEach(function(network) {
                        if(network.SSID == $scope.wifi.ssid) { 
                            $scope.wifi.bssid = network.BSSID;
                            $scope.wifi.level = network.level;
                            $scope.wifi.frequency = network.frequency;
                            $scope.wifi.config = network.capabilities; 
                        }
                    });
    
                    // update scope values in template
                    $scope.$apply();
                }, 
                wifiError
            );
        }
    
        // get device's ip adress
        networkinterface.getWiFiIPAddress(
            function(ip, subnet) {  
                $scope.wifi.ip = ip;
                $scope.wifi.subnet= subnet;
    
                // update scope values in template
                $scope.$apply();
            }, 
            function(error) { 
                $cordovaToast.show("WiFi IP Adresse konnte nicht ermittelt werden: " + error, "long", "center");
                $cordovaDialogs.beep(1); 
            }
        );
    
        // get device's carrier ip adress
        networkinterface.getCarrierIPAddress(function (ip) { 
            $scope.wifi.vendorIp = ip; 
    
            // update scope values in template
            $scope.$apply();
        });
    }
    
    // read network (wifi) - error
    function wifiError(error) {
        $cordovaToast.show("WiFi Fehler: " + error, "long", "center");
        $cordovaDialogs.beep(1);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-04-12
      • 2012-05-25
      • 2023-03-04
      • 1970-01-01
      • 2015-01-08
      • 2012-07-08
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      相关资源
      最近更新 更多