我已经选择了一个蓝牙设备,我正在尝试注册连接和断开连接通知
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
。
答案 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(已连接))