I have a Bluetooth device already selected and I am trying to register connect and disconnect notifications
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
}
}
I haven't problems with the forDisconnectNotification
but I get next error with the forConnectNotifications
:
Incorrect argument label in call (have 'forConnectNotifications:selector:', expected 'forDisconnectNotification:selector:')
It's so strange because even in the official doc it is documented forConnectNotifications
instead of forDisconnectNotification
.
Ok, the forDisconnectNotification
can be associated with the instance 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.
This one is the proper way to implement it IOBluetoothDevice.register(forConnectNotifications: self, selector: #selector(connected))