react-native-ble-manager 11.5.2 → 11.5.4
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/android/src/main/java/it/innove/BleManager.java +7 -3
- package/android/src/main/java/it/innove/CompanionScanner.java +5 -0
- package/android/src/main/java/it/innove/DefaultScanManager.java +6 -0
- package/android/src/main/java/it/innove/LegacyScanManager.java +5 -0
- package/android/src/main/java/it/innove/ScanManager.java +2 -0
- package/ios/BleManager.swift +22 -17
- package/package.json +1 -1
|
@@ -2,8 +2,6 @@ package it.innove;
|
|
|
2
2
|
|
|
3
3
|
import static android.app.Activity.RESULT_OK;
|
|
4
4
|
import static android.bluetooth.BluetoothProfile.GATT;
|
|
5
|
-
import static android.os.Build.VERSION_CODES.LOLLIPOP;
|
|
6
|
-
import static android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE;
|
|
7
5
|
import android.annotation.SuppressLint;
|
|
8
6
|
import android.app.Activity;
|
|
9
7
|
import android.bluetooth.BluetoothAdapter;
|
|
@@ -167,7 +165,7 @@ class BleManager extends ReactContextBaseJavaModule {
|
|
|
167
165
|
filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
|
|
168
166
|
IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
|
|
169
167
|
intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
|
170
|
-
if (Build.VERSION.SDK_INT >=
|
|
168
|
+
if (Build.VERSION.SDK_INT >= 34){
|
|
171
169
|
// Google in 2023 decides that flag RECEIVER_NOT_EXPORTED or RECEIVER_EXPORTED should be explicit set SDK 34(UPSIDE_DOWN_CAKE) on registering receivers.
|
|
172
170
|
// Also the export flags are available on Android 8 and higher, should be used with caution so that don't break compability with that devices.
|
|
173
171
|
context.registerReceiver(mReceiver, filter, Context.RECEIVER_EXPORTED);
|
|
@@ -565,11 +563,17 @@ class BleManager extends ReactContextBaseJavaModule {
|
|
|
565
563
|
break;
|
|
566
564
|
case BluetoothAdapter.STATE_TURNING_OFF:
|
|
567
565
|
state = "turning_off";
|
|
566
|
+
if (scanManager != null) {
|
|
567
|
+
scanManager.setScanning(false);
|
|
568
|
+
}
|
|
568
569
|
break;
|
|
569
570
|
case BluetoothAdapter.STATE_OFF:
|
|
570
571
|
default:
|
|
571
572
|
// should not happen as per https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getState()
|
|
572
573
|
state = "off";
|
|
574
|
+
if (scanManager != null) {
|
|
575
|
+
scanManager.setScanning(false);
|
|
576
|
+
}
|
|
573
577
|
break;
|
|
574
578
|
}
|
|
575
579
|
}
|
|
@@ -64,10 +64,12 @@ public class CompanionScanner {
|
|
|
64
64
|
if (peripheral != null && scanCallback != null) {
|
|
65
65
|
scanCallback.invoke(null, peripheral.asWritableMap());
|
|
66
66
|
scanCallback = null;
|
|
67
|
+
bleManager.sendEvent("BleManagerCompanionPeripheral", peripheral.asWritableMap());
|
|
67
68
|
}
|
|
68
69
|
} else {
|
|
69
70
|
scanCallback.invoke(null, null);
|
|
70
71
|
scanCallback = null;
|
|
72
|
+
bleManager.sendEvent("BleManagerCompanionPeripheral", null);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
} else {
|
|
@@ -122,6 +124,9 @@ public class CompanionScanner {
|
|
|
122
124
|
Log.d(LOG_TAG, "companion failure: " + charSequence);
|
|
123
125
|
scanCallback.invoke("Companion association failed: " + charSequence.toString());
|
|
124
126
|
scanCallback = null;
|
|
127
|
+
WritableMap map = Arguments.createMap();
|
|
128
|
+
map.putString("error", charSequence.toString());
|
|
129
|
+
bleManager.sendEvent("BleManagerCompanionFailure", map);
|
|
125
130
|
}
|
|
126
131
|
|
|
127
132
|
@Override
|
|
@@ -255,7 +255,13 @@ public class DefaultScanManager extends ScanManager {
|
|
|
255
255
|
}
|
|
256
256
|
};
|
|
257
257
|
|
|
258
|
+
@Override
|
|
258
259
|
public boolean isScanning() {
|
|
259
260
|
return isScanning;
|
|
260
261
|
}
|
|
262
|
+
|
|
263
|
+
@Override
|
|
264
|
+
public void setScanning(boolean scanning) {
|
|
265
|
+
isScanning = scanning;
|
|
266
|
+
}
|
|
261
267
|
}
|
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
|
}
|