IOBluetoothDevice 注册不适用于 forConnectNotifications

IOBluetoothDevice register doesn't work with forConnectNotifications

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

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:')

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

好的,forDisconnectNotification可以关联到实例https://developer.apple.com/documentation/iobluetooth/iobluetoothdevice/1429542-register but the forConnectNotifications must be associated with the type https://developer.apple.com/documentation/iobluetooth/iobluetoothdevice/1433370-register

这是实现它的正确方法 IOBluetoothDevice.register(forConnectNotifications: self, 选择器: #selector(connected))