react-native-ble-manager 10.1.1 → 10.1.3
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.
|
@@ -175,7 +175,15 @@ class BleManager extends ReactContextBaseJavaModule {
|
|
|
175
175
|
if (getCurrentActivity() == null)
|
|
176
176
|
callback.invoke("Current activity not available");
|
|
177
177
|
else
|
|
178
|
-
|
|
178
|
+
{
|
|
179
|
+
try{
|
|
180
|
+
getCurrentActivity().startActivityForResult(intentEnable, ENABLE_REQUEST);
|
|
181
|
+
}catch(Exception e){
|
|
182
|
+
callback.invoke("Current activity not available");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
179
187
|
} else
|
|
180
188
|
callback.invoke();
|
|
181
189
|
}
|
|
@@ -5,6 +5,7 @@ import android.bluetooth.le.ScanRecord;
|
|
|
5
5
|
import android.bluetooth.le.ScanResult;
|
|
6
6
|
import android.os.Build;
|
|
7
7
|
import android.os.ParcelUuid;
|
|
8
|
+
import android.annotation.SuppressLint;
|
|
8
9
|
|
|
9
10
|
import com.facebook.react.bridge.Arguments;
|
|
10
11
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
@@ -15,6 +16,7 @@ import com.facebook.react.bridge.WritableMap;
|
|
|
15
16
|
import java.util.Map;
|
|
16
17
|
|
|
17
18
|
|
|
19
|
+
@SuppressLint("MissingPermission")
|
|
18
20
|
public class DefaultPeripheral extends Peripheral {
|
|
19
21
|
|
|
20
22
|
private ScanRecord advertisingData;
|
|
@@ -36,6 +38,10 @@ public class DefaultPeripheral extends Peripheral {
|
|
|
36
38
|
WritableMap advertising = Arguments.createMap();
|
|
37
39
|
|
|
38
40
|
try {
|
|
41
|
+
map.putString("name", device.getName());
|
|
42
|
+
map.putString("id", device.getAddress()); // mac address
|
|
43
|
+
map.putInt("rssi", advertisingRSSI);
|
|
44
|
+
|
|
39
45
|
advertising.putMap("manufacturerData", byteArrayToWritableMap(advertisingDataBytes));
|
|
40
46
|
|
|
41
47
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
@@ -52,7 +52,7 @@ public class Peripheral extends BluetoothGattCallback {
|
|
|
52
52
|
public static final int GATT_INSUFFICIENT_AUTHENTICATION = 5;
|
|
53
53
|
public static final int GATT_AUTH_FAIL = 137;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
protected final BluetoothDevice device;
|
|
56
56
|
private final Map<String, NotifyBufferContainer> bufferedCharacteristics;
|
|
57
57
|
protected volatile byte[] advertisingDataBytes = new byte[0];
|
|
58
58
|
protected volatile int advertisingRSSI;
|
package/ios/BleManager.m
CHANGED
|
@@ -17,7 +17,7 @@ RCT_EXPORT_MODULE();
|
|
|
17
17
|
@synthesize manager;
|
|
18
18
|
@synthesize peripherals;
|
|
19
19
|
@synthesize scanTimer;
|
|
20
|
-
bool hasListeners;
|
|
20
|
+
static bool hasListeners = NO;
|
|
21
21
|
|
|
22
22
|
- (instancetype)init
|
|
23
23
|
{
|
|
@@ -185,7 +185,7 @@ bool hasListeners;
|
|
|
185
185
|
|
|
186
186
|
|
|
187
187
|
|
|
188
|
-
- (NSString *) centralManagerStateToString: (
|
|
188
|
+
- (NSString *) centralManagerStateToString: (CBManagerState)state
|
|
189
189
|
{
|
|
190
190
|
switch (state) {
|
|
191
191
|
case CBManagerStateUnknown:
|
|
@@ -406,9 +406,11 @@ RCT_EXPORT_METHOD(scan:(NSArray *)serviceUUIDStrings timeoutSeconds:(nonnull NSN
|
|
|
406
406
|
}
|
|
407
407
|
[manager scanForPeripheralsWithServices:serviceUUIDs options:options];
|
|
408
408
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
409
|
+
if ([timeoutSeconds floatValue] > 0) {
|
|
410
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
411
|
+
self.scanTimer = [NSTimer scheduledTimerWithTimeInterval:[timeoutSeconds floatValue] target:self selector:@selector(stopScanTimer:) userInfo: nil repeats:NO];
|
|
412
|
+
});
|
|
413
|
+
}
|
|
412
414
|
callback(@[]);
|
|
413
415
|
}
|
|
414
416
|
|
|
@@ -972,7 +974,6 @@ RCT_EXPORT_METHOD(requestMTU:(NSString *)deviceUUID mtu:(NSInteger)mtu callback:
|
|
|
972
974
|
}
|
|
973
975
|
NSLog(@"Characteristics For Service Discover");
|
|
974
976
|
|
|
975
|
-
NSString *peripheralUUIDString = [peripheral uuidAsString];
|
|
976
977
|
NSMutableSet *characteristicsForService = [NSMutableSet new];
|
|
977
978
|
[characteristicsForService addObjectsFromArray:service.characteristics];
|
|
978
979
|
[retrieveServicesLatches setObject:characteristicsForService forKey:service.UUID.UUIDString];
|