所以你必须在 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-appsI 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 更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 15:44