在 IOS 12-Xamarin 上获取已连接 WIFI 的 SSID(针对 iOS 13 更新) [英] Getting the SSID of the CONNECTED WIFI on IOS 12- Xamarin (Updated for iOS 13)

查看:38
本文介绍了在 IOS 12-Xamarin 上获取已连接 WIFI 的 SSID(针对 iOS 13 更新)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将连接的 wifi 的 ssid 连接到我的 iPhone.安装 Xcode 10 并更新 Visual Studio for Mac 和 Visual Studio 2017 后,它返回一个空的 ssid.

这是我获取 ssid 的一段代码:

 公共覆盖字符串 GetCurrentWiFi(){字符串 ssid = "";尝试{string[] 支持的接口;状态码状态;if ((status = CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterfaces)) != StatusCode.OK){}别的{foreach(supportedInterfaces 中的 var 项目){NSD字典信息;status = CaptiveNetwork.TryCopyCurrentNetworkInfo(item, out info);如果(状态!= StatusCode.OK){继续;}ssid = info[CaptiveNetwork.NetworkInfoKeySSID].ToString();}}}抓住{}返回ssid;}

我尝试为这里提到的 iOS 12 应用程序添加访问 WiFi 信息"权利,但该应用程序仍然获得空的 ssid:

所以你必须在 appid 中检查 Access WiFi Infomation.

I could get the ssid of the connected wifi to my iPhone. After Installing Xcode 10 and Updating Visual Studio for Mac and Visual Studio 2017, it returns me an empty ssid.

This is my piece of code for getting the ssid:

        public override string GetCurrentWiFi()
    {
        String ssid = "";
        try
        {
            string[] supportedInterfaces;
            StatusCode status;
            if ((status = CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterfaces)) != StatusCode.OK)
            {

            }
            else
            {
                foreach (var item in supportedInterfaces)
                {
                    NSDictionary info;
                    status = CaptiveNetwork.TryCopyCurrentNetworkInfo(item, out info);
                    if (status != StatusCode.OK)
                    {
                        continue;
                    }
                    ssid = info[CaptiveNetwork.NetworkInfoKeySSID].ToString();
                }
            }
        }
        catch
        {

        }
        return ssid;
    }

I tried to add "Access WiFi Information" entitlement for iOS 12 app as it is mentioned here but the app still get an empty ssid:https://forums.xamarin.com/discussion/139476/adding-access-wifi-information-entitlement-for-ios-12-apps

I would be thankful if anyone could help.

RESOLVED: I applied Access WIFI Information for my Apple ID. Then I regenerated my Provisioning profile again and open it in my Xcode. Do not forget to add Entitlements.plist in the Custom Entertainments in the ios Bundle Signing. Now it works correctly.

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".

解决方案

To use this function in iOS 12 and later, enable the Access WiFi Information capability for your app .

So you have to check Access WiFi Infomation in appid.

这篇关于在 IOS 12-Xamarin 上获取已连接 WIFI 的 SSID(针对 iOS 13 更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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