I am looking for a way to obtain information (at least the name) of the current connected wlan network in objective-c for iOS5.
I need this because we are currently developing an application that do not work in a particular network. In this network (on our university) the port is closed that we need to connect to the server. But there is another network also available and we want to tell the user that he has to switch the network if he is connected to the aforementioned one.
I do not even know where to start. Does anyone have an idea or any hints?
Thanks and regards
An SSID is the name of a WiFi network. So if you are looking for the SSID for the WiFi network you are connected to on your iPhone, you will go to Settings > WiFi and there you will see the name (or SSID) of the network.
You can likely find your router's default network name, or SSID, on a sticker on the back or side of the router. It may also appear in the router's manual.
To do this, open System Preferences, and then click Network. Select Wi-Fi in the sidebar, and then click Advanced. In the Wi-Fi tab, you will see a list of networks. This list is mainly there so you can choose an order of preference for joining networks.
From iOS >= 4.1 it's possible to obtain SSID of wireless network that device is currenctly connected to.
For this you'd use function CNCopyCurrentNetworkInfo
Details on implemenation are available on SO: iPhone get SSID without private library
It is possible to get the current wifi information from the Captive Network. In the past, apple actually disabled this for a while, but they seems to re-enabled it due to strong request. It is also possible that they decide to close this in the future.
The information we can get is BSSID
, SSID
, SSIDDATA
. BSSID
is the unique address for wifi, SSID
is the current wifi name, SSIDDATA
is the hex representation for the SSID
.
func printCurrentWifiInfo() {
if let interface = CNCopySupportedInterfaces() {
for i in 0..<CFArrayGetCount(interface) {
let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interface, i)
let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
if let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString), let interfaceData = unsafeInterfaceData as? [String : AnyObject] {
// connected wifi
print("BSSID: \(interfaceData["BSSID"]), SSID: \(interfaceData["SSID"]), SSIDDATA: \(interfaceData["SSIDDATA"])")
} else {
// not connected wifi
}
}
}
}
NSArray *interFaceNames = (__bridge_transfer id)CNCopySupportedInterfaces();
for (NSString *name in interFaceNames) {
NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)name);
NSLog[@"wifi info: bssid: %@, ssid:%@, ssidData: %@", info[@"BSSID"], info[@"SSID"], info[@"SSIDDATA"]];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With