在Xamarin.iOS,iOS 13中获取连接的wifi网络的SSID



从iOS 12转到13后,我再也无法获得连接的wifi网络的SSID。

我尝试了在中提出的iOS 13解决方案这个问题但是没有结果。

我之前为iOS 12成功编写的代码(此外,现在不推荐使用"CaptiveNetwork"(:

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();
return ssid;
}
}
}

有什么建议吗?

更新iOS 13:苹果宣布iOS 13,CNCopyCurrentNetworkInfo API将不再返回有效的Wi-Fi SSID和BSSID信息。

如果您的应用程序需要有效的Wi-Fi SSID和BSSID信息才能运行,您可以执行以下操作:·对于附件安装应用程序,请使用NEHotSpotConfiguration API,该应用程序现在可以选择传递应用程序预期连接的SSID热点的前缀。·对于其他类型的应用程序,使用CoreLocation API请求用户同意访问位置信息。

因此,我以以下方式更新了上述解决方案:

将此密钥添加到您的信息列表:

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

使用CoreLocation API请求用户同意访问位置信息。

private void GetLocationConsent()
{
var manager = new CLLocationManager();
manager.AuthorizationChanged += (sender, args) => {
Console.WriteLine("Authorization changed to: {0}", args.Status);
};
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
manager.RequestWhenInUseAuthorization();
}

在调用"CaptiveNetwork"之前,请先调用GetLocationConsent((函数。

最新更新