调用事件功能时,CoreWLAN CWEventDelegate EXC_BAD_ACCESS

时间:2019-01-02 13:37:53

标签: swift macos corewlan

所以我正在使用CoreWLAN,我需要注册一些事件;我首先尝试了一个事件CWEventType.ssidDidChange。然后,根据Apple Docs,我具有适当的功能来处理它func ssidDidChangeForWiFiInterface(withName interfaceName: String)。但是,当事件触发时(我将我的wifi重置为模拟SSID更改),我收到了类似这样的错误Thread 2: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

我正在使用的Apple文档页面: 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

这是我的代码:

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")
    }
}

0 个答案:

没有答案