react-native-ble-manager 8.0.2 → 8.3.0

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/README.md CHANGED
@@ -43,7 +43,7 @@ The library support the react native autolink feature.
43
43
 
44
44
  <!-- Only when targeting Android 12 or higher -->
45
45
  <!-- Please make sure you read the following documentation to have a
46
- better understanging of the new permissions.
46
+ better understanding of the new permissions.
47
47
  https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location
48
48
  -->
49
49
 
@@ -131,10 +131,11 @@ Returns a `Promise` object.
131
131
  - `seconds` - `Integer` - the amount of seconds to scan.
132
132
  - `allowDuplicates` - `Boolean` - [iOS only] allow duplicates in device scanning
133
133
  - `scanningOptions` - `JSON` - [Android only] after Android 5.0, user can control specific ble scan behaviors:
134
- - `numberOfMatches` - `Number` - corresponding to [`setNumOfMatches`](<https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder.html#setNumOfMatches(int)>)
135
- - `matchMode` - `Number` - corresponding to [`setMatchMode`](<https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder.html#setMatchMode(int)>)
136
- - `scanMode` - `Number` - corresponding to [`setScanMode`](<https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder.html#setScanMode(int)>)
137
- - `reportDelay` - `Number` - corresponding to [`setReportDelay`](<https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder.html#setReportDelay(long)>)
134
+ - `numberOfMatches` - `Number` - [Android only] corresponding to [`setNumOfMatches`](<https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder.html#setNumOfMatches(int)>)
135
+ - `matchMode` - `Number` - [Android only] corresponding to [`setMatchMode`](<https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder.html#setMatchMode(int)>)
136
+ - `scanMode` - `Number` - [Android only] corresponding to [`setScanMode`](<https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder.html#setScanMode(int)>)
137
+ - `reportDelay` - `Number` - [Android only] corresponding to [`setReportDelay`](<https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder.html#setReportDelay(long)>)
138
+ - `phy` - `Number` - [Android only] corresponding to [`setPhy`](https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder#setPhy(int))
138
139
 
139
140
  **Examples**
140
141
 
@@ -780,6 +781,8 @@ A peripheral was disconnected.
780
781
 
781
782
  - `peripheral` - `String` - the id of the peripheral
782
783
  - `status` - `Number` - [Android only] disconnect [`reasons`](<https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html#onConnectionStateChange(android.bluetooth.BluetoothGatt,%20int,%20int)>)
784
+ - `domain` - `String` - [iOS only] disconnect error domain
785
+ - `code` - `Number` - [iOS only] disconnect error code (<https://developer.apple.com/documentation/corebluetooth/cberror/code>)
783
786
 
784
787
  ### BleManagerPeripheralDidBond
785
788
 
@@ -802,3 +805,15 @@ _For more on performing long-term bluetooth actions in the background:_
802
805
  [iOS Bluetooth State Preservation and Restoration](https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW10)
803
806
 
804
807
  [iOS Relaunch Conditions](https://developer.apple.com/library/archive/qa/qa1962/_index.html)
808
+
809
+ ### BleManagerDidUpdateNotificationStateFor [iOS only]
810
+
811
+ The peripheral received a request to start or stop providing notifications for a specified characteristic's value.
812
+
813
+ **Arguments**
814
+
815
+ - `peripheral` - `String` - the id of the peripheral
816
+ - `characteristic` - `String` - the UUID of the characteristic
817
+ - `isNotifying` - `Boolean` - Is the characteristic notifying or not
818
+ - `domain` - `String` - [iOS only] error domain
819
+ - `code` - `Number` - [iOS only] error code
@@ -732,4 +732,19 @@ class BleManager extends ReactContextBaseJavaModule {
732
732
  // Keep: Required for RN built in Event Emitter Calls.
733
733
  }
734
734
 
735
+ @Override
736
+ public void onCatalystInstanceDestroy() {
737
+ try {
738
+ // Disconnect all known peripherals, otherwise android system will think we are still connected
739
+ // while we have lost the gatt instance
740
+ disconnectPeripherals();
741
+ }catch(Exception e) {
742
+ Log.d(LOG_TAG, "Could not disconnect peripherals", e);
743
+ }
744
+
745
+ if (scanManager != null) {
746
+ // Stop scan in case one was started to stop events from being emitted after destroy
747
+ scanManager.stopScan(args -> {});
748
+ }
749
+ }
735
750
  }
@@ -2,6 +2,7 @@ package it.innove;
2
2
 
3
3
 
4
4
  import android.bluetooth.BluetoothAdapter;
5
+ import android.bluetooth.BluetoothDevice;
5
6
  import android.bluetooth.le.ScanCallback;
6
7
  import android.bluetooth.le.ScanFilter;
7
8
  import android.bluetooth.le.ScanResult;
@@ -54,6 +55,16 @@ public class LollipopScanManager extends ScanManager {
54
55
  if (options.hasKey("reportDelay")) {
55
56
  scanSettingsBuilder.setReportDelay(options.getInt("reportDelay"));
56
57
  }
58
+
59
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && options.hasKey("phy")) {
60
+ int phy = options.getInt("phy");
61
+ if (phy == BluetoothDevice.PHY_LE_CODED && getBluetoothAdapter().isLeCodedPhySupported()) {
62
+ scanSettingsBuilder.setPhy(BluetoothDevice.PHY_LE_CODED);
63
+ }
64
+ if (phy == BluetoothDevice.PHY_LE_2M && getBluetoothAdapter().isLe2MPhySupported()) {
65
+ scanSettingsBuilder.setPhy(BluetoothDevice.PHY_LE_2M);
66
+ }
67
+ }
57
68
 
58
69
  if (serviceUUIDs.size() > 0) {
59
70
  for(int i = 0; i < serviceUUIDs.size(); i++){
package/index.d.ts CHANGED
@@ -28,6 +28,7 @@ declare module "react-native-ble-manager" {
28
28
  matchMode?: number;
29
29
  scanMode?: number;
30
30
  reportDelay?: number;
31
+ phy?: number;
31
32
  }
32
33
 
33
34
  export function scan(
package/ios/BleManager.m CHANGED
@@ -76,7 +76,7 @@ bool hasListeners;
76
76
 
77
77
  - (NSArray<NSString *> *)supportedEvents
78
78
  {
79
- return @[@"BleManagerDidUpdateValueForCharacteristic", @"BleManagerStopScan", @"BleManagerDiscoverPeripheral", @"BleManagerConnectPeripheral", @"BleManagerDisconnectPeripheral", @"BleManagerDidUpdateState", @"BleManagerCentralManagerWillRestoreState"];
79
+ return @[@"BleManagerDidUpdateValueForCharacteristic", @"BleManagerStopScan", @"BleManagerDiscoverPeripheral", @"BleManagerConnectPeripheral", @"BleManagerDisconnectPeripheral", @"BleManagerDidUpdateState", @"BleManagerCentralManagerWillRestoreState", @"BleManagerDidUpdateNotificationStateFor"];
80
80
  }
81
81
 
82
82
 
@@ -110,6 +110,9 @@ bool hasListeners;
110
110
  if (characteristic == nil){
111
111
  return;
112
112
  }
113
+ if (hasListeners) {
114
+ [self sendEventWithName:@"BleManagerDidUpdateNotificationStateFor" body:@{@"peripheral": peripheral.uuidAsString, @"characteristic": characteristic.UUID.UUIDString, @"isNotifying": @(false), @"domain": [error domain], @"code": @(error.code)}];
115
+ }
113
116
  }
114
117
 
115
118
  NSString *key = [self keyForPeripheral: peripheral andCharacteristic:characteristic];
@@ -138,6 +141,9 @@ bool hasListeners;
138
141
  [stopNotificationCallbacks removeObjectForKey:key];
139
142
  }
140
143
  }
144
+ if (hasListeners) {
145
+ [self sendEventWithName:@"BleManagerDidUpdateNotificationStateFor" body:@{@"peripheral": peripheral.uuidAsString, @"characteristic": characteristic.UUID.UUIDString, @"isNotifying": @(characteristic.isNotifying)}];
146
+ }
141
147
  }
142
148
 
143
149
 
@@ -860,7 +866,11 @@ RCT_EXPORT_METHOD(requestMTU:(NSString *)deviceUUID mtu:(NSInteger)mtu callback:
860
866
  }
861
867
 
862
868
  if (hasListeners) {
863
- [self sendEventWithName:@"BleManagerDisconnectPeripheral" body:@{@"peripheral": [peripheral uuidAsString]}];
869
+ if (error) {
870
+ [self sendEventWithName:@"BleManagerDisconnectPeripheral" body:@{@"peripheral": [peripheral uuidAsString], @"domain": [error domain], @"code": @(error.code)}];
871
+ } else {
872
+ [self sendEventWithName:@"BleManagerDisconnectPeripheral" body:@{@"peripheral": [peripheral uuidAsString]}];
873
+ }
864
874
  }
865
875
  }
866
876
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-manager",
3
- "version": "8.0.2",
3
+ "version": "8.3.0",
4
4
  "description": "A BLE module for react native.",
5
5
  "main": "BleManager",
6
6
  "types": "./index.d.ts",