我正在开发一个基于物联网的离子项目。我需要在我的应用中获取连接的WiFi 的详细信息(WiFi名称和密码)。我有used这个插件。
cordova plugin add cordova-plugin-network-information
但是这个插件并没有提供连接WiFi的名称和密码等信息。是否有任何插件或方法来获取连接的wifi细节? 谢谢
答案 0 :(得分: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);
}