Skip to content

Commit

Permalink
fix(ios): do not reject disconnect call when already disconnected
Browse files Browse the repository at this point in the history
(cherry picked from commit e6873e6)
  • Loading branch information
pwespi committed Apr 10, 2021
1 parent 63808ef commit f488140
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ios/Plugin/DeviceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ class DeviceManager: NSObject, CBCentralManagerDelegate {
func disconnect(_ device: Device, _ callback: @escaping Callback) {
let key = "disconnect|\(device.getId())"
self.callbackMap[key] = callback
if device.isConnected() == false {
self.resolve(key, "Disconnected.")
return
}
print("Disconnecting from peripheral", device.getPeripheral())
self.centralManager.cancelPeripheralConnection(device.getPeripheral())
self.setTimeout(key, "Disconnection timeout.")
Expand Down
2 changes: 1 addition & 1 deletion ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class BluetoothLe: CAPPlugin {

@objc func disconnect(_ call: CAPPluginCall) {
guard self.getDeviceManager(call) != nil else { return }
guard let device = self.getDevice(call) else { return }
guard let device = self.getDevice(call, checkConnection: false) else { return }
self.deviceManager?.disconnect(device, {(success, message) -> Void in
if success {
call.resolve()
Expand Down

0 comments on commit f488140

Please sign in to comment.