Skip to content

Commit

Permalink
Fixed issue #319 causing "API MISUSE" warning from CoreBluetooth (#323)
Browse files Browse the repository at this point in the history
* Fixed issue #319 causing "API MISUSE" warning from CoreBluetooth

* Improvements after review
  • Loading branch information
wojciech-kulik authored and minixT committed Apr 12, 2019
1 parent e88f8a1 commit e5f8a57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Source/CharacteristicNotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class CharacteristicNotificationManager {
}

private func setNotifyValue(_ enabled: Bool, for characteristic: Characteristic) {
guard peripheral.state == .connected else {
RxBluetoothKitLog.w("\(peripheral.logDescription) is not connected." +
" Changing notification state for not connected peripheral is not possible.")
return
}
peripheral.setNotifyValue(enabled, for: characteristic.characteristic)
}
}
6 changes: 4 additions & 2 deletions Source/Connector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ class Connector {
disposable.dispose()
let isConnected = strongSelf.connectedBox.read { $0.contains(peripheral.identifier) }
if isConnected {
strongSelf.disconnectingBox.write { $0.insert(peripheral.identifier) }
strongSelf.centralManager.cancelPeripheralConnection(peripheral.peripheral)
if strongSelf.centralManager.state == .poweredOn {
strongSelf.disconnectingBox.write { $0.insert(peripheral.identifier) }
strongSelf.centralManager.cancelPeripheralConnection(peripheral.peripheral)
}
strongSelf.connectedBox.write { $0.remove(peripheral.identifier) }
}
}
Expand Down

0 comments on commit e5f8a57

Please sign in to comment.