BSSID returning null

Hi SIr,


I am using the below code and API to fetch BSSID, but BSSID value is always null.

Please suggest a better way to fetch BSSID value:


API:

CWInterface *wif = [wifiInterface interface];

NSString *bssidName = wif.bssid;

NSLog(@"BSSID %@",bssidName);


Output:

2020-04-16 14:37:50.976 mysample[99186:5816581] BSSID (null)

Try starting CoreLocation and then checking the networks. BSSID should be available then.

Something like this should work:


- (void)startScan {
    CLLocationManager *mgr = [[CLLocationManager alloc] init];
    if (@available(macOS 10.15, *)) {
        [mgr requestAlwaysAuthorization];
        [mgr startUpdatingLocation];
        [self scanForWiFi];
    }
}

- (void)scanForWiFi {
      CWInterface* wifiInterface = [[CWWiFiClient sharedWiFiClient] interface];
      NSArray *wifiList = [[wifiInterface scanForNetworksWithName:nil error:nil] allObjects];

      for (CWNetwork *currentWifi in wifiList) {
          NSString *wifiInfo = [NSString stringWithFormat:@"SSID: %@ - BSSID %@ - RSSI: %ld",
                                currentWifi.ssid, currentWifi.bssid, (long)currentWifi.rssiValue];
          NSLog(@"Wi-Fi Info: %@", wifiInfo);
      }
}



Matt Eaton

DTS Engineering, CoreOS

meaton3 at apple.com

I'm trying to do the same from a command line utility written in Swift. I enabled "Location" resource access under Signing & Capabilities. I also tried adding an Info.plist file with the "Create Info.plist Section in Binary", so I could include a location authorization description. I see the prompt for location access and am able to get location updates, but the bssid is still nil. Here's my code:


import CoreWLAN
import CoreLocation

class Delegate: NSObject, CLLocationManagerDelegate {
    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        print("changed auth status: \(status.rawValue)")

        if status == .authorizedAlways {
            print("Scanning for WiFi networks")
            let interface = CWWiFiClient.shared().interface()!

            let networks = try! interface.scanForNetworks(withName: nil)

            for n in networks {
                print("\(n.ssid) - \(n.bssid)")
            }

        }
    }
    func locationManager(_ manager: CLLocationManager, didUpdateTo newLocation: CLLocation, from oldLocation: CLLocation) {
        print("Got location: \(newLocation)")
    }
}

let delegate = Delegate()
let lm = CLLocationManager()
lm.requestAlwaysAuthorization()
lm.startUpdatingLocation()
lm.delegate = delegate


RunLoop.main.run()
print("exiting")

I recommend that you start by repeating your test in a small test app. That’ll tell you whether this is a problem that’s specific to the command-line environment.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
BSSID returning null
 
 
Q