【问题标题】:Error getting network SSID in Xamarin.IOS在 Xamarin.IOS 中获取网络 SSID 时出错
【发布时间】:2021-02-15 14:51:42
【问题描述】:

我在 Info.plist 中添加了这个键:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Your Description</string>

并在 Entitlements.plist 中选中“添加对 wifi 信息的访问权限”。

我也向用户请求了 Location 的权限:

var manager = new CLLocationManager();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
    manager.RequestWhenInUseAuthorization();

我点击“允许”,然后我想获取wifi信息:

if (CLLocationManager.Status is CLAuthorizationStatus.Authorized || 
    CLLocationManager.Status is CLAuthorizationStatus.AuthorizedAlways || 
    CLLocationManager.Status is CLAuthorizationStatus.AuthorizedWhenInUse)
{
  if (CaptiveNetwork.TryGetSupportedInterfaces(out string[] supportedInterfaces) == StatusCode.OK)
  {
    foreach (var item in supportedInterfaces)
    {
      if (CaptiveNetwork.TryCopyCurrentNetworkInfo(item, out NSDictionary info) == StatusCode.OK)
      {
        var ssid = info[CaptiveNetwork.NetworkInfoKeySSID].ToString();
        System.Console.WriteLine(ssid);
      }
    }
  }
}

但 info 变量始终为空。

我想获取已连接 wifi 网络的 SSID 和保护级别(WPA、WPA2 等)。

我使用 iPhone SE iOS 14.4。软件版本:

  • Microsoft Visual Studio Community 2019 版本 16.8.4
  • Xamarin 16.8.000.261
  • Xamarin.iOS 和 Xamarin.Mac SDK 14.8.0.3 (c51fabee8)
  • XCode 12.3

【问题讨论】:

  • 您是否为您的应用启用了访问 WiFi 信息功能?
  • @WendyZang-MSFT 在 Entitlements.plist 中,是的。但是我需要参与 Apple Developer Program,并在 Apple Developer Portal 中启用 Access WiFi Information 功能吗?
  • 您可以查看以下链接了解更多详情。 stackoverflow.com/questions/52539526/…

标签: ios xamarin xamarin.ios captivenetwork


【解决方案1】:

我需要参与 Apple Developer Program,并在 Apple Developer Portal 中启用 Access WiFi Information 功能。

【讨论】:

    猜你喜欢
    • 2020-02-20
    • 2017-01-28
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 2011-06-08
    • 2014-05-27
    • 1970-01-01
    • 2015-08-31
    相关资源
    最近更新 更多