在Xamarin.iOS,iOS 13中获取连接的wifi网络的SSID [英] Getting SSID of the connected wifi network in Xamarin.iOS, iOS 13

查看:154
本文介绍了在Xamarin.iOS,iOS 13中获取连接的wifi网络的SSID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从iOS 12传递到13之后,我再也无法获得所连接的wifi网络的SSID.

After passing from iOS 12 to 13 I am no more able to get the SSID of the connected wifi network.

我尝试了针对iOS 13中提出的解决方案这个问题但没有结果.

I tried the solution for iOS 13 proposed in this question but with no result.

我之前在iOS 12上成功使用的代码(而且不建议使用'CaptiveNetwork'):

My previous successful code for iOS 12 (moreover 'CaptiveNetwork' is deprecated now):

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更新:Apple宣布iOS 13(CNCopyCurrentNetworkInfo API)将不再返回有效的Wi-Fi SSID和BSSID信息

Updated for iOS 13: Apple announced that iOS 13, the CNCopyCurrentNetworkInfo API will no longer return valid Wi-Fi SSID and BSSID information.

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

If your app requires valid Wi-Fi SSID and BSSID information to function, you can do the following: · For accessory setup apps, use the NEHotSpotConfiguration API, which now has the option to pass a prefix of the SSID hotspot your app expects to connect to. · For other types of apps, use the CoreLocation API to request the user’s consent to access location information.

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

So, I updated the above solution in the following way:

将此密钥添加到您的info.plist:

Add this key to your info.plist:

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

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

Use the CoreLocation API to request the user’s consent to access location information.

    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()函数.

Call the GetLocationConsent() function before calling the "CaptiveNetwork".

这篇关于在Xamarin.iOS,iOS 13中获取连接的wifi网络的SSID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆