I'm trying to display all available WIFI connections. It doesn't work. Here is my code:
import Foundation
import CoreWLAN
var cwInterface = CWInterface()
do {
let routers = try cwInterface.scanForNetworksWithSSID(nil)
print(routers)
} catch let error as NSError {
print("Error: \(error.localizedDescription)")
}
I don't get any result. What I'm doing wrong?
It works if you initialize CWInterface with an interface name, like "en1".
But it's better to not use harcoded names, so we'll also use
CWWiFiClient.sharedWiFiClient().interface()
which returns the default WIFI interface.Example of a class to manage all this:
Call it with the default interface:
Or with an interface name:
Results contains all the scanned networks: