Created
November 8, 2013 14:30
-
-
Save dannycabrera/7371787 to your computer and use it in GitHub Desktop.
Xamarin.iOS GetSSID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | |
} | |
} |
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?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Use the CoreLocation API to request the user’s consent to access location information.
Call the GetLocationConsent() function before calling the "CaptiveNetwork".