Access BSSID MacOS

I don't understand what permissions need to be given for this code to operate. I cannot seem to work out why I'm not able to see a BSSID.

I think I've given sandbox the appropriate permissions AND I've added some to the Target Properties for good measure. Yet, cannot get BSSID.

import SwiftUI
import CoreWLAN
import CoreLocation
struct ContentView: View {
@State private var currentBSSID: String = "Loading..."
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Current BSSID:")
Text(currentBSSID)
}
.padding()
.onAppear(perform: fetchBSSID)
}
func fetchBSSID() {
if let iface2 = CWWiFiClient.shared().interface() {
print("✅ Found Wi-Fi interface: \(iface2.interfaceName ?? "nil")")
} else {
print("❌ No Wi-Fi interface found")
}
if let iface = CWWiFiClient.shared().interface(),
let bssid = iface.bssid() {
currentBSSID = bssid
} else {
currentBSSID = "Not connected"
print("✅ BSSID: \(currentBSSID)")
}
}
}
#Preview {
ContentView()
}

Output - WifI interface is found but BSSID is not found.

Answered by DTS Engineer in 833622022

If you care about user privileges, as set in System Settings > Privacy & Security, don’t use Sign to Run Locally. That results in an ad-hoc signature, which means your code has no designated requirement, which means the system can’t track the privilege from one build of your app to the next. See TN3127 Inside Code Signing: Requirements for more about this.

Instead, choose an Apple Development signing identity.

Beyond that, you are correct that getting the BSSID requires you to have the Location privilege. You wrote:

Written by tb589 in 833414022
If you run it in Xcode, won't work.

What do you mean by “run it in Xcode”? Are you choosing Product > Run? Or are you talking about the SwiftUI preview?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

This works if you run it from outside Xcode. If you run it in Xcode, won't work.

import SwiftUI
import CoreWLAN
import SystemConfiguration.CaptiveNetwork
import CoreLocation
class LocationDelegate: NSObject, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
var onAuthorizationGranted: (() -> Void)?
override init() {
super.init()
locationManager.delegate = self
}
func requestLocation() {
locationManager.requestWhenInUseAuthorization()
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .authorizedWhenInUse, .authorizedAlways:
onAuthorizationGranted?()
default:
break
}
}
}
struct ContentView: View {
@State private var currentBSSID: String = "Loading..."
let locationDelegate = LocationDelegate()
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Current BSSID:")
Text(currentBSSID)
}
.padding()
.onAppear {
locationDelegate.onAuthorizationGranted = {
fetchBSSID()
}
locationDelegate.requestLocation()
}
}
func fetchBSSID() {
if let iface2 = CWWiFiClient.shared().interface() {
print("✅ Found Wi-Fi interface: \(iface2.interfaceName ?? "nil")")
} else {
print("❌ No Wi-Fi interface found")
}
if let iface = CWWiFiClient.shared().interface(),
let bssid = iface.bssid() {
currentBSSID = bssid
} else {
currentBSSID = "Not connected"
print("✅ BSSID: \(currentBSSID)")
}
}
}
#Preview {
ContentView()

}

If you care about user privileges, as set in System Settings > Privacy & Security, don’t use Sign to Run Locally. That results in an ad-hoc signature, which means your code has no designated requirement, which means the system can’t track the privilege from one build of your app to the next. See TN3127 Inside Code Signing: Requirements for more about this.

Instead, choose an Apple Development signing identity.

Beyond that, you are correct that getting the BSSID requires you to have the Location privilege. You wrote:

Written by tb589 in 833414022
If you run it in Xcode, won't work.

What do you mean by “run it in Xcode”? Are you choosing Product > Run? Or are you talking about the SwiftUI preview?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Access BSSID MacOS
 
 
Q