-
-
Save dannycabrera/7371787 to your computer and use it in GitHub Desktop.
| public static string GetSSID(bool withMacAddress = true) | |
| { | |
| try { | |
| NSDictionary dict; | |
| var status = CaptiveNetwork.TryCopyCurrentNetworkInfo ("en0", out dict); | |
| if (status == StatusCode.NoKey) | |
| return ""; | |
| var bssid = dict [CaptiveNetwork.NetworkInfoKeyBSSID]; | |
| var ssid = dict [CaptiveNetwork.NetworkInfoKeySSID]; | |
| //var ssiddat = dict [CaptiveNetwork.NetworkInfoKeySSIDData]; | |
| if (withMacAddress) | |
| return string.Format ("{0} [{1}]", ssid, bssid); | |
| else | |
| return ssid.ToString (); | |
| /* | |
| foreach (string intf in CaptiveNetwork.GetSupportedInterfaces()) { | |
| NSDictionary dict2; | |
| CaptiveNetwork.TryCopyCurrentNetworkInfo (intf, out dict2); | |
| //if (status == StatusCode.NoKey) | |
| // return ""; | |
| var bssid2 = dict [CaptiveNetwork.NetworkInfoKeyBSSID]; | |
| var ssid2 = dict [CaptiveNetwork.NetworkInfoKeySSID]; | |
| var ssiddat2 = dict [CaptiveNetwork.NetworkInfoKeySSIDData]; | |
| } | |
| */ | |
| } catch { | |
| return ""; | |
| } | |
| } |
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".
Thanks for the input @sheraz16.
Thank you, Sheraz16 I implemented it and it worked on my project, is there a way to get the signal strength of the WIFI?
on IOS12 dict is null, solution?