IOBluetoothDevice寄存器不适用于forConnectNotifications

时间:2018-07-28 10:46:49

标签: swift macos iobluetooth

我已经选择了一个蓝牙设备,我正在尝试注册连接和断开连接通知

func selectDevice() {
    var promptRes = Int32?((deviceSelector?.runModal())!)
    if promptRes == Int32(kIOBluetoothUISuccess) {
        self.selectedDevice = deviceSelector?.getResults().first as? IOBluetoothDevice
        selectedDevice?
            .register(forConnectNotifications: self, selector: #selector(connected))
        selectedDevice?
            .register(forDisconnectNotification: self, selector: #selector(disconnected))
        self.connectDevice()
    } else {
        self.selectedDevice = nil
    }
}

我对forDisconnectNotification没问题,但是我遇到了forConnectNotifications的下一个错误:

Incorrect argument label in call (have 'forConnectNotifications:selector:', expected 'forDisconnectNotification:selector:')

enter image description here

这很奇怪,因为即使在正式文档中也记录了forConnectNotifications而不是forDisconnectNotification

1 个答案:

答案 0 :(得分:1)

好的,forDisconnectNotification可以与实例https://developer.apple.com/documentation/iobluetooth/iobluetoothdevice/1429542-register关联,但是forConnectNotifications必须与类型https://developer.apple.com/documentation/iobluetooth/iobluetoothdevice/1433370-register关联。

这是实现它的正确方法             IOBluetoothDevice.register(forConnectNotifications:自我,选择器:#selector(已连接))