documentation radar: FB10364979
On how to do this, I meant with location services. So I managed to muddle through some of it (y'all really need to look at how MS does their dev docs, the sample code for things here is really skimpy)
What I have so far:
in my "main" file (not the contentview file):
class locationDelegate: NSObject, CLLocationManagerDelegate {
func theLocationAuthStatus(_manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
print("changed auth status: \(status.rawValue)")
switch status.rawValue {
case 0:
print("Not Determined")
case 1:
print("Restricted")
case 2:
print("Denied")
case 3:
print("Authorized Always")
case 4:
print("Authorized when in use")
default:
print("None of the above")
}
}
}
In my ContentView file:
@State var myLocationManager = CLLocationManager()
<lots of swiftui UI stuff>
.onAppear {
let myDelegate = locationDelegate()
myLocationManager.requestWhenInUseAuthorization()
myLocationManager.startUpdatingLocation()
myLocationManager.delegate = myDelegate
myLocationManager.delegate
print(myLocationManager.authorizationStatus.rawValue)
let myLocationManagerAuthStatus = myLocationManager.authorizationStatus.rawValue
if myLocationManagerAuthStatus == 3 || myLocationManagerAuthStatus == 4 {
//get BSSID
print("we're authorized")
currentWAPMAC = getBSSID()
}
//set up the SSID value
currentSSID = getSSID()
//get the Wifi Channel. if it's a zero,
//channel is actually nil
currentChannel = getCWChannelNumber()
//set up the RSSI
signalStrength = getRSSI()
//BRING THA NOIZE
signalNoise = getNoise()
//get the SNR as a formatted string via NumberFormatter
signalToNoise = getSNR(theSig: signalStrength, theNoise: signalNoise)
//get transmit rate
dataRate = getTransmitRate()
//get current time
self.theCurrentTime = getCurrentTime()
//stop the timer
self.stopTimer()
}
create the interface object:
func getWifiInterface() -> CWInterface {
let theWirelessClient = CWWiFiClient.shared()
let theWirelessInterface = theWirelessClient.interface()
return theWirelessInterface!
}
//moved this from contentview to here. Probably a better place for all this
var theWifiInterface: CWInterface = getWifiInterface()
the getBSSID() function:
func getBSSID() -> String {
if let theBSSID = theWifiInterface.bssid() {
return theBSSID
} else {
let theBSSID = "no BSSID"
return theBSSID
}
}
So on run,
print(myLocationManager.authorizationStatus.rawValue) prints a 3, so cool, we're auth'd and the dialog has been appearing nice and consistent-like
and the
if myLocationManagerAuthStatus == 3 || myLocationManagerAuthStatus == 4 {
//get BSSID
print("we're authorized")
currentWAPMAC = getBSSID()
}
prints "we're authorized" as expected, but no BSSID returned. Everything else, the SSID, the channel, the Signal/Noise strengths, the Data Rate, that I get fine, but I can't get the BSSID. I know I'm missing something simple, but i'm completely puzzled as to what.
Thanks!