Регистр IOBluetoothDevice не работает с forConnectNotifications

Устройство Bluetooth уже выбрано, и я пытаюсь зарегистрировать уведомления о подключении и отключении

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,

1 ответ

Решение

Хорошо, forDisconnectNotification может быть связан с экземпляром https://developer.apple.com/documentation/iobluetooth/iobluetoothdevice/1429542-register но forConnectNotifications должен быть связан с типом https://developer.apple.com/documentation/iobluetooth/iobluetoothdevice/1433370-register.

Это правильный способ его реализации. IOBluetoothDevice.register(forConnectNotifications: self, selector: #selector(connected))

Другие вопросы по тегам