So I'm using CoreWLAN, and I needed to register some events; I got started by trying one event, CWEventType.ssidDidChange
. Then I have the appropriate function according to Apple Docs to handle it func ssidDidChangeForWiFiInterface(withName interfaceName: String)
. But when the event fires (I reset my wifi to simulate an SSID change), I get an error like this Thread 2: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
.
Apple documentation pages I was using: https://developer.apple.com/documentation/corewlan/cwwificlient/1512439-startmonitoringevent https://developer.apple.com/documentation/corewlan/cweventtype https://developer.apple.com/documentation/corewlan/cweventdelegate https://developer.apple.com/documentation/corewlan/cweventdelegate/1512422-ssiddidchangeforwifiinterface
This is my code:
import Foundation
import CoreWLAN
import Cocoa
class WLANMonitor: CWEventDelegate {
var client: CWWiFiClient = CWWiFiClient.shared();
init() {
self.client.delegate = self
}
func registerEvents() {
puts("Registering for SSID change...")
do {
try client.startMonitoringEvent(with: CWEventType.ssidDidChange);
} catch {
print("Error");
}
}
func ssidDidChangeForWiFiInterface(withName interfaceName: String)
{
print("Changed SSID")
}
}