1

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

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.

4

1 回答 1

1

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

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

于 2018-07-28T11:09:21.873 回答