如何使用Ionic3获取iOS 13 WiFi SSID?

时间:2019-10-03 07:11:43

标签: ios ionic3 ios13

我已经使用WifiWizard插件获取SSID,但是在iOS 13上无法使用。它给我SSID作为“ Wi-Fi”关键字,它没有显示实际连接的WiFi SSID。

在使用中,我已经在info.plist中添加了位置信息,并且还尝试更新本机iOS代码,但是它不起作用。

我尝试使用WifiWizard2插件,但这也无法正常工作。

getWifiName() {
    WifiWizard.getCurrentSSID(ssidHandler => {
      console.log(ssidHandler);
      ssidHandler = ssidHandler.toString().replace("\"", "");
      ssidHandler = ssidHandler.toString().replace("\"", "");
      this.connectedTo = ssidHandler;
      this.ssidHandler(ssidHandler);
    }, fail => {
      this.goToSettingsButton = false;
      console.log(fail);
    });
  }

我想要iOS 13中的当前WiFi SSID,就像我连接到ABC Wifi网络一样,那么它应该给我SSID为ABC。

1 个答案:

答案 0 :(得分:0)

嘿,我遇到了同样的问题,并通过安装cordova-plugin-geolocation解决了该问题。 Here's the official site

基本上是->

请注意,由于我的Ionic 3.20.1,我正在安装特定版本

$ ionic cordova plugin add cordova-plugin-geolocation@3

$ npm install @ionic-native/geolocation@4.10

import { Geolocation } from '@ionic-native/geolocation';

...

constructor(private geolocation: Geolocation) {}

...

async yourAwesomeFunction() {
 try {
   pos = await this.geolocation.getCurrentPosition();
   if (pos) WifiWizard.getCurrentSSID((ssid) => {
   //your stuff
});
 } catch((err) => {
  console.error(err);
})

然后将其添加到config.xml

<config-file overwrite="true" parent="NSLocationWhenInUseUsageDescription" platform="ios" target="*-Info.plist">
     <string>Allow the app to know your location</string>
</config-file>

然后,我将库CoreLocation(“常规”的XCODE选项卡)添加到了项目中。