I want to get all the WiFi networks available in a region and their SSID value. But the problem is how to get the SSID of all the WiFi network available even if I am not connected to one.
-
@EnricoSusatyo i have same problem i can't have get all available wifi list.Jatin Devani– Jatin Devani2016-08-17 12:13:37 +00:00Commented Aug 17, 2016 at 12:13
-
Not easily. Scanning wifi networks is a security threat.Sulthan– Sulthan2017-01-27 21:08:24 +00:00Commented Jan 27, 2017 at 21:08
-
4I found similar questions asked on SO with a quick google search, the common answer is that while you can you are not supposed to due to Apples rulesuser2640633– user26406332017-01-28 04:45:30 +00:00Commented Jan 28, 2017 at 4:45
-
yeah I found one similar question here stackoverflow.com/questions/5198716/…ramacode– ramacode2017-02-03 10:22:50 +00:00Commented Feb 3, 2017 at 10:22
3 Answers
iOS 12
You must enable Access WiFi Information 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
First;
import SystemConfiguration.CaptiveNetwork
Then;
func getInterfaces() -> Bool { guard let unwrappedCFArrayInterfaces = CNCopySupportedInterfaces() else { print("this must be a simulator, no interfaces found") return false } guard let swiftInterfaces = (unwrappedCFArrayInterfaces as NSArray) as? [String] else { print("System error: did not come back as array of Strings") return false } for interface in swiftInterfaces { print("Looking up SSID info for \(interface)") // en0 guard let unwrappedCFDictionaryForInterface = CNCopyCurrentNetworkInfo(interface) else { print("System error: \(interface) has no information") return false } guard let SSIDDict = (unwrappedCFDictionaryForInterface as NSDictionary) as? [String: AnyObject] else { print("System error: interface information is not a string-keyed dictionary") return false } for d in SSIDDict.keys { print("\(d): \(SSIDDict[d]!)") } } return true }
1 Comment
Here my class that prints the WIFI network name
import UIKit
import Foundation
import SystemConfiguration.CaptiveNetwork
class FirstView: UIViewController
{
@IBOutlet weak var label: UILabel!
override func viewDidLoad()
{
super.viewDidLoad()
let ssid = self.getWiFiName()
print("SSID: \(ssid)")
}
func getWiFiName() -> String? {
var ssid: String?
if let interfaces = CNCopySupportedInterfaces() as NSArray? {
for interface in interfaces {
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
break
}
}
}
return ssid
}
}
Yes it is possible to list all nearby WiFi networks.You need to complete a questionnaire at https://developer.apple.com/contact/network-extension, and then you can use NEHotspotHelper to return a list of hotspots. Technical Q&A https://developer.apple.com/library/archive/qa/qa1942/_index.html