Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #319 causing "API MISUSE" warning from CoreBluetooth #323

Merged
merged 3 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
wojciech-kulik marked this conversation as resolved.
Show resolved Hide resolved
}
strongSelf.connectedBox.write { $0.remove(peripheral.identifier) }
}
}
Expand Down