Skip to content

Commit

Permalink
Fix handling error in didUpdateNotificationStateFor
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosinigaglia committed Dec 11, 2023
1 parent bfe59c8 commit 6acdf54
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions ios/BleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ class BleManager: RCTEventEmitter, CBCentralManagerDelegate, CBPeripheralDelegat
}

@objc func getMaximumWriteValueLengthForWithResponse(_ peripheralUUID: String,
callback: @escaping RCTResponseSenderBlock) {
callback: @escaping RCTResponseSenderBlock) {
NSLog("getMaximumWriteValueLengthForWithResponse")

guard let peripheral = peripherals[peripheralUUID] else {
Expand Down Expand Up @@ -717,7 +717,7 @@ class BleManager: RCTEventEmitter, CBCentralManagerDelegate, CBPeripheralDelegat
}
}
}


func centralManager(_ central: CBCentralManager,
didConnect peripheral: CBPeripheral) {
Expand Down Expand Up @@ -1072,41 +1072,43 @@ class BleManager: RCTEventEmitter, CBCentralManagerDelegate, CBPeripheralDelegat
"code": error._code
])
}
} else {
if hasListeners {
sendEvent(withName: "BleManagerDidUpdateNotificationStateFor", body: [
"peripheral": peripheral.uuidAsString(),
"characteristic": characteristic.uuid.uuidString.lowercased(),
"isNotifying": characteristic.isNotifying
])
}
}

let key = Helper.key(forPeripheral: peripheral, andCharacteristic: characteristic)

if characteristic.isNotifying {
if let error = error {
if notificationCallbacks[key] != nil {
if let error = error {
invokeAndClearDictionary(&notificationCallbacks, withKey: key, usingParameters: [error])
} else {
if BleManager.verboseLogging {
NSLog("Notification began on \(characteristic.uuid)")
}
invokeAndClearDictionary(&notificationCallbacks, withKey: key, usingParameters: [])
}
invokeAndClearDictionary(&notificationCallbacks, withKey: key, usingParameters: [error])
}
} else {
// Notification has stopped
if stopNotificationCallbacks[key] != nil {
if error != nil {
invokeAndClearDictionary(&stopNotificationCallbacks, withKey: key, usingParameters: [error as Any])
} else {
if BleManager.verboseLogging {
NSLog("Notification ended on \(characteristic.uuid)")
}
invokeAndClearDictionary(&stopNotificationCallbacks, withKey: key, usingParameters: [error])
}
} else {
if characteristic.isNotifying {
if BleManager.verboseLogging {
NSLog("Notification began on \(characteristic.uuid)")
}
if notificationCallbacks[key] != nil {
invokeAndClearDictionary(&notificationCallbacks, withKey: key, usingParameters: [])
}
} else {
// Notification has stopped
if BleManager.verboseLogging {
NSLog("Notification ended on \(characteristic.uuid)")
}
if stopNotificationCallbacks[key] != nil {
invokeAndClearDictionary(&stopNotificationCallbacks, withKey: key, usingParameters: [])
}
}
}
if hasListeners {
sendEvent(withName: "BleManagerDidUpdateNotificationStateFor", body: [
"peripheral": peripheral.uuidAsString(),
"characteristic": characteristic.uuid.uuidString.lowercased(),
"isNotifying": characteristic.isNotifying
])
}
}

func peripheral(_ peripheral: CBPeripheral,
Expand Down

0 comments on commit 6acdf54

Please sign in to comment.