How to get Wifi SSID in iOS9 after CaptiveNetwork is deprecated and calls for Wifi name are already blocked
In the GM for iOS 9, it seems like this is enabled again. In fact, it's not even listed as deprecated in the online documentation, however the CaptiveNetwork header file does have the following:
CNCopySupportedInterfaces (void) __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_8, __MAC_NA, __IPHONE_4_1, __IPHONE_9_0, CN_DEPRECATION_NOTICE);
So, it is working in the iOS 9 GM, but not sure for how long :)
How do I use CaptiveNetwork to get the current WiFi Hotspot Name
You need to find out which networks are available, and then pass them into CNCopyCurrentNetworkInfo. For example:
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
...and you can then use the kCNNetworkInfoKeySSID on the dictionary you've got back (myDict) to find out the SSID. Don't forget to release/manage memory appropriately.
iOS get current wlan network name
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
iPhone get SSID without private library
As of iOS 7 or 8, you can do this (need Entitlement for iOS 12+ as shown below):
@import SystemConfiguration.CaptiveNetwork;
/** Returns first non-empty SSID network info dictionary.
* @see CNCopyCurrentNetworkInfo */
- (NSDictionary *)fetchSSIDInfo {
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
NSLog(@"%s: Supported interfaces: %@", __func__, interfaceNames);
NSDictionary *SSIDInfo;
for (NSString *interfaceName in interfaceNames) {
SSIDInfo = CFBridgingRelease(
CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
NSLog(@"%s: %@ => %@", __func__, interfaceName, SSIDInfo);
BOOL isNotEmpty = (SSIDInfo.count > 0);
if (isNotEmpty) {
break;
}
}
return SSIDInfo;
}
Example output:
2011-03-04 15:32:00.669 ShowSSID[4857:307] -[ShowSSIDAppDelegate fetchSSIDInfo]: Supported interfaces: (
en0
)
2011-03-04 15:32:00.693 ShowSSID[4857:307] -[ShowSSIDAppDelegate fetchSSIDInfo]: en0 => {
BSSID = "ca:fe:ca:fe:ca:fe";
SSID = XXXX;
SSIDDATA = <01234567 01234567 01234567>;
}
Note that no ifs are supported on the simulator. Test on your device.
iOS 12
You must enable access wifi info from capabilities.
Important
To use this function in iOS 12 and later, enable the Access WiFi Information capability for your app in Xcode. When you enable this capability, Xcode automatically adds the Access WiFi Information entitlement to your entitlements file and App ID. Documentation link
Swift 4.2
func getConnectedWifiInfo() -> [AnyHashable: Any]? {
if let ifs = CFBridgingRetain( CNCopySupportedInterfaces()) as? [String],
let ifName = ifs.first as CFString?,
let info = CFBridgingRetain( CNCopyCurrentNetworkInfo((ifName))) as? [AnyHashable: Any] {
return info
}
return nil
}
Related Topics
How to Autoplay a Youtube Video in a Uiwebview
iPad Safari - Make Keyboard Disappear
How to Change the Status Bar Background Color and Text Color on iOS 13
iOS Firebase Push Notifications:How to Give Firebase User's Device Token and Send Notification
How to Exclude Notes and Reminders Apps from the Uiactivityviewcontroller
How to Deserialize a JSON String into an Nsdictionary? (For iOS 5+)
Detect Permission of Camera in iOS
Is This Possible to Apply the Alternative Icon to the iOS Application
How to Detect iPhone Is on Silent Mode
Sprite Kit & Playing Sound Leads to App Termination
How to Get the Name of Image Picked Through Photo Library in Iphone
How to Get Text/String from Nth Line of Uilabel
Detecting a Point in a Mkpolygon Broke with iOS7 (Cgpathcontainspoint)
Passing Data Between View Controllers Using Segue
Get the Current Scroll Position of a Swiftui Scrollview
How to Determine Whether Code Is Running in Debug/Release Build
Uitapgesturerecognizer Breaks Uitableview Didselectrowatindexpath