react-native-ble-manager 8.0.1 → 8.0.2

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
@@ -30,15 +30,37 @@ The library support the react native autolink feature.
30
30
 
31
31
  ```xml
32
32
  // file: android/app/src/main/AndroidManifest.xml
33
- ...
34
- <uses-permission android:name="android.permission.BLUETOOTH"/>
35
- <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
36
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
33
+ <!-- Add xmlns:tools -->
34
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
35
+ xmlns:tools="http://schemas.android.com/tools"
36
+ package="YOUR_PACKAGE_NAME">
37
+
38
+ <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
39
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
40
+
41
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="28"/>
42
+ <uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" tools:targetApi="Q"/>
43
+
44
+ <!-- Only when targeting Android 12 or higher -->
45
+ <!-- Please make sure you read the following documentation to have a
46
+ better understanging of the new permissions.
47
+ https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location
48
+ -->
49
+
50
+ <!-- If your app doesn't use Bluetooth scan results to derive physical location information,
51
+ you can strongly assert that your app
52
+ doesn't derive physical location. -->
53
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"
54
+ android:usesPermissionFlags="neverForLocation"
55
+ tools:targetApi="s" />
56
+
57
+ <!-- Needed only if your app looks for Bluetooth devices. -->
58
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
59
+ <!-- Needed only if your app makes the device discoverable to Bluetooth devices. -->
60
+ <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
37
61
  ...
38
62
  ```
39
63
 
40
- In Android API 29 >= you need to use "ACCESS_FINE_LOCATION" instead of "ACCESS_COARSE_LOCATION".
41
-
42
64
  If you need communication while the app is not in the foreground you need the "ACCESS_BACKGROUND_LOCATION" permission.
43
65
 
44
66
  ##### iOS - Update Info.plist
@@ -53,6 +75,7 @@ In iOS >= 13 you need to add the `NSBluetoothAlwaysUsageDescription` string key.
53
75
  - Android API >= 29 require the ACCESS_FINE_LOCATION permission to scan for peripherals.
54
76
  React-Native 0.63.X started targeting Android API 29.
55
77
  - Before write, read or start notification you need to call `retrieveServices` method
78
+ - Because location and bluetooth permissions are runtime permissions, you **must** request these permissions at runtime along with declaring them in your manifest.
56
79
 
57
80
  ## Example
58
81
 
@@ -758,6 +781,14 @@ A peripheral was disconnected.
758
781
  - `peripheral` - `String` - the id of the peripheral
759
782
  - `status` - `Number` - [Android only] disconnect [`reasons`](<https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html#onConnectionStateChange(android.bluetooth.BluetoothGatt,%20int,%20int)>)
760
783
 
784
+ ### BleManagerPeripheralDidBond
785
+
786
+ A bond with a peripheral was established
787
+
788
+ **Arguments**
789
+
790
+ Object with information about the device
791
+
761
792
  ### BleManagerCentralManagerWillRestoreState [iOS only]
762
793
 
763
794
  This is fired when [`centralManager:WillRestoreState:`](https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/1518819-centralmanager) is called (app relaunched in the background to handle a bluetooth event).
@@ -193,7 +193,7 @@ class BleManager extends ReactContextBaseJavaModule {
193
193
  for (Iterator<Map.Entry<String, Peripheral>> iterator = peripherals.entrySet().iterator(); iterator
194
194
  .hasNext(); ) {
195
195
  Map.Entry<String, Peripheral> entry = iterator.next();
196
- if (!entry.getValue().isConnected()) {
196
+ if (!(entry.getValue().isConnected() || entry.getValue().isConnecting())) {
197
197
  iterator.remove();
198
198
  }
199
199
  }
@@ -53,6 +53,7 @@ public class Peripheral extends BluetoothGattCallback {
53
53
  protected byte[] advertisingDataBytes = new byte[0];
54
54
  protected int advertisingRSSI;
55
55
  private boolean connected = false;
56
+ private boolean connecting = false;
56
57
  private ReactContext reactContext;
57
58
 
58
59
  private BluetoothGatt gatt;
@@ -104,6 +105,7 @@ public class Peripheral extends BluetoothGattCallback {
104
105
  if (!connected) {
105
106
  BluetoothDevice device = getDevice();
106
107
  this.connectCallback = callback;
108
+ this.connecting = true;
107
109
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
108
110
  Log.d(BleManager.LOG_TAG, " Is Or Greater than M $mBluetoothDevice");
109
111
  gatt = device.connectGatt(activity, false, this, BluetoothDevice.TRANSPORT_LE);
@@ -252,6 +254,10 @@ public class Peripheral extends BluetoothGattCallback {
252
254
  return connected;
253
255
  }
254
256
 
257
+ public boolean isConnecting() {
258
+ return connecting;
259
+ }
260
+
255
261
  public BluetoothDevice getDevice() {
256
262
  return device;
257
263
  }
@@ -288,6 +294,7 @@ public class Peripheral extends BluetoothGattCallback {
288
294
  newState = BluetoothProfile.STATE_DISCONNECTED;
289
295
  }
290
296
 
297
+ connecting = false;
291
298
  if (newState == BluetoothProfile.STATE_CONNECTED) {
292
299
  connected = true;
293
300
 
@@ -846,6 +853,10 @@ public class Peripheral extends BluetoothGattCallback {
846
853
  if (! doWrite(characteristic, data, callback)) {
847
854
  callback.invoke("Write failed");
848
855
  writeCallback = null;
856
+ } else {
857
+ if (BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE == writeType) {
858
+ callback.invoke();
859
+ }
849
860
  }
850
861
  } else {
851
862
  int dataLength = data.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-manager",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "description": "A BLE module for react native.",
5
5
  "main": "BleManager",
6
6
  "types": "./index.d.ts",