react-native-ble-manager 11.5.3 → 11.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/BleManager.swift +22 -17
- package/ios/Helper.swift +2 -2
- package/package.json +1 -1
package/ios/BleManager.swift
CHANGED
|
@@ -122,14 +122,17 @@ class BleManager: RCTEventEmitter, CBCentralManagerDelegate, CBPeripheralDelegat
|
|
|
122
122
|
// Helper method to call the callbacks for a specific peripheral and clear the queue
|
|
123
123
|
func invokeAndClearDictionary(_ dictionary: inout Dictionary<String, [RCTResponseSenderBlock]>, withKey key: String, usingParameters parameters: [Any]) {
|
|
124
124
|
serialQueue.sync {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
invokeAndClearDictionary_THREAD_UNSAFE(&dictionary, withKey: key, usingParameters: parameters)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
func invokeAndClearDictionary_THREAD_UNSAFE(_ dictionary: inout Dictionary<String, [RCTResponseSenderBlock]>, withKey key: String, usingParameters parameters: [Any]) {
|
|
130
|
+
if let peripheralCallbacks = dictionary[key] {
|
|
131
|
+
for callback in peripheralCallbacks {
|
|
132
|
+
callback(parameters)
|
|
132
133
|
}
|
|
134
|
+
|
|
135
|
+
dictionary.removeValue(forKey: key)
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
138
|
|
|
@@ -1078,16 +1081,18 @@ class BleManager: RCTEventEmitter, CBCentralManagerDelegate, CBPeripheralDelegat
|
|
|
1078
1081
|
NSLog("Read value [\(characteristic.uuid)]: \( value.hexadecimalString())")
|
|
1079
1082
|
}
|
|
1080
1083
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
"
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1084
|
+
serialQueue.sync {
|
|
1085
|
+
if readCallbacks[key] != nil {
|
|
1086
|
+
invokeAndClearDictionary_THREAD_UNSAFE(&readCallbacks, withKey: key, usingParameters: [NSNull(), characteristic.value!.toArray()])
|
|
1087
|
+
} else {
|
|
1088
|
+
if hasListeners {
|
|
1089
|
+
sendEvent(withName: "BleManagerDidUpdateValueForCharacteristic", body: [
|
|
1090
|
+
"peripheral": peripheral.uuidAsString(),
|
|
1091
|
+
"characteristic": characteristic.uuid.uuidString.lowercased(),
|
|
1092
|
+
"service": characteristic.service!.uuid.uuidString.lowercased(),
|
|
1093
|
+
"value": characteristic.value!.toArray()
|
|
1094
|
+
])
|
|
1095
|
+
}
|
|
1091
1096
|
}
|
|
1092
1097
|
}
|
|
1093
1098
|
}
|
package/ios/Helper.swift
CHANGED
|
@@ -165,13 +165,13 @@ class Helper {
|
|
|
165
165
|
|
|
166
166
|
static func key(forPeripheral peripheral: CBPeripheral,
|
|
167
167
|
andCharacteristic characteristic: CBCharacteristic) -> String {
|
|
168
|
-
return "\(String(describing: peripheral.uuidAsString))|\(characteristic.uuid)"
|
|
168
|
+
return "\(String(describing: peripheral.uuidAsString()))|\(characteristic.uuid)"
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
static func key(forPeripheral peripheral: CBPeripheral,
|
|
172
172
|
andCharacteristic characteristic: CBCharacteristic,
|
|
173
173
|
andDescriptor descriptor: CBDescriptor) -> String {
|
|
174
|
-
return "\(String(describing: peripheral.uuidAsString))|\(characteristic.uuid)|\(descriptor.uuid)"
|
|
174
|
+
return "\(String(describing: peripheral.uuidAsString()))|\(characteristic.uuid)|\(descriptor.uuid)"
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
static func findDescriptor(fromUUID UUID: CBUUID, characteristic: CBCharacteristic) -> CBDescriptor? {
|