Getting SSID of the connected wifi network in Xamarin.iOS, iOS 13

本小妞迷上赌 提交于 2021-01-29 08:44:43

问题


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

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

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;
        }
    }
}

Any suggestion?


回答1:


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

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:

Add this key to your info.plist:

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

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();

}

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



来源:https://stackoverflow.com/questions/58542114/getting-ssid-of-the-connected-wifi-network-in-xamarin-ios-ios-13

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!